Plugin can describe itself.
authorCMDR furrycat <elite@furrycat.net>
Wed, 26 Oct 2016 10:25:31 +0000 (11:25 +0100)
committerCMDR furrycat <elite@furrycat.net>
Wed, 26 Oct 2016 10:25:31 +0000 (11:25 +0100)
app.py
plugins/__init__.py
plugins/feeds.py

diff --git a/app.py b/app.py
index 19f8c0d..5cce8c3 100644 (file)
--- a/app.py
+++ b/app.py
@@ -1459,6 +1459,24 @@ bot.db = db
 plugins.set_client(client)
 
 @asyncio.coroutine
+def builtin_commands(message, command, raw):
+  if command == 'plugins':
+    all_plugins = list(plugins.plugins())
+    if len(all_plugins):
+      lines = []
+      for name in all_plugins:
+        description = plugins.description(name)
+        if description is not None:
+          lines.append('{}: {}'.format(name, description))
+        else:
+          lines.append(name)
+      yield from bot.say_many(message.channel, lines)
+    else:
+      yield from bot.say(message.channel, 'shrugs')
+    return True
+  return False
+
+@asyncio.coroutine
 def process_module(message, command, raw):
   for module, params in modules.items():
     if command in params['commands']:
@@ -1635,7 +1653,9 @@ def on_message(message):
   if m is None:
     return
   command = m.group(1)
-  result = yield from plugins.handle_command(message, command, raw)
+  result = yield from builtin_commands(message, command, raw)
+  if not result:
+    result = yield from plugins.handle_command(message, command, raw)
   if not result:
     yield from process_module(message, command, raw)
 
index b4fdf50..9b7d187 100644 (file)
@@ -39,6 +39,10 @@ class Plugins(object):
   def plugins(self):
     return self.loaded.keys()
 
+  def description(self, name):
+    if self.has_method(name, 'description'):
+      return self.call_method(name, 'description')
+
   def get_plugin(self, name):
     if name not in self.loaded:
       return None
index d9c8f50..a0441a6 100644 (file)
@@ -21,6 +21,9 @@ class Feeds(DBConnection):
     super(Feeds, self).__init__(filename)
     self.create_tables()
 
+  def description(self):
+    return 'Handles RSS feeds.'
+
   def create_tables(self):
     self.open_db()
     cursor = self.query('create table if not exists feeds (id char(36) not null, bot_id varchar(32) not null, server_id varchar(32) not null, channel_id varchar(32) not null, description varchar(64), url varchar(128) not null, date boolean not null default true, summary boolean not null default false, link_json varchar(256), enabled boolean not null default true)')