From 85f2a9e03d4f634fd030b40a8964143c179db525 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Mon, 25 Sep 2017 12:50:26 -0700 Subject: [PATCH] bots: Add basic metadata with failover, used on running only. --- zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py | 5 +++++ zulip_bots/zulip_bots/bots/xkcd/xkcd.py | 5 +++++ zulip_bots/zulip_bots/lib.py | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py index 9659273..506695a 100644 --- a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py @@ -18,6 +18,11 @@ class WikipediaHandler(object): kind of external issue tracker as well. ''' + META = { + 'name': 'Wikipedia', + 'description': 'Searches Wikipedia for a term and returns the top article.', + } + def usage(self): return ''' This plugin will allow users to directly search diff --git a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py index d99c212..c1baca4 100644 --- a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py @@ -14,6 +14,11 @@ class XkcdHandler(object): commands. ''' + META = { + 'name': 'XKCD', + 'description': 'Fetches comic strips from https://xkcd.com.', + } + def usage(self): return ''' This plugin allows users to fetch a comic strip provided by diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index edc816f..5c5b63d 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -187,7 +187,17 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name): state_handler = StateHandler() + # Set default bot_details, then override from class, if provided + bot_details = { + 'name': bot_name.capitalize(), + 'description': "", + } + bot_details.update(getattr(lib_module.handler_class, 'META', {})) + if not quiet: + print("Running {} Bot:".format(bot_details['name'])) + if bot_details['description'] != "": + print("\n\t{}".format(bot_details['description'])) print(message_handler.usage()) def handle_message(message):