Include plugin commands in help output.
authorCMDR furrycat <elite@furrycat.net>
Sat, 29 Oct 2016 09:41:34 +0000 (10:41 +0100)
committerCMDR furrycat <elite@furrycat.net>
Sat, 29 Oct 2016 09:41:34 +0000 (10:41 +0100)
app.py
plugins.py

diff --git a/app.py b/app.py
index 54771f7..07e9cd7 100644 (file)
--- a/app.py
+++ b/app.py
@@ -160,21 +160,14 @@ def show_help(message, *args):
     command = None
 
   if command is None:
+    valid_commands = ['coords', 'close_to', 'distance', 'edts', 'find', 'fuel_usage', 'galmath', 'id', 'raikogram', 'time']
+    valid_commands += plugins.valid_commands()
     lines = [
       '<@{}>, the cat-like robot from the 34th century of the future, recognises these commands (and more):'.format(client.user.id),
-      '```',
-      'announce',
-      'coords',
-      'bling',
-      'close_to',
-      'distance',
-      'edts',
-      'find',
-      'fuel_usage',
-      'galmath',
-      'id',
-      'raikogram',
-      'time',
+      '```'
+    ]
+    lines += sorted(valid_commands)
+    lines += [
       '```',
       'Send `help COMMAND` for help on a specific command.'
     ]
index 36e63a7..fe78446 100644 (file)
@@ -40,6 +40,14 @@ class Plugins(object):
   def plugins(self):
     return self.loaded.keys()
 
+  def valid_commands(self):
+    commands = []
+    for name in self.plugins():
+      plugin_commands = self.call_method(name, 'valid_commands')
+      if plugin_commands is not None:
+        commands += plugin_commands
+    return sorted(list(set(commands)))
+
   def description(self, name):
     if self.has_method(name, 'description'):
       return self.call_method(name, 'description')