From: CMDR furrycat Date: Wed, 26 Oct 2016 10:25:31 +0000 (+0100) Subject: Plugin can describe itself. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=19402dd8abbdb660fc5d718b176afe336b38d8a0;p=furrycat%2Fcatbot.git Plugin can describe itself. --- diff --git a/app.py b/app.py index 19f8c0d..5cce8c3 100644 --- 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) diff --git a/plugins/__init__.py b/plugins/__init__.py index b4fdf50..9b7d187 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -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 diff --git a/plugins/feeds.py b/plugins/feeds.py index d9c8f50..a0441a6 100644 --- a/plugins/feeds.py +++ b/plugins/feeds.py @@ -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)')