usage = "bot: help [plugin name], bot: plugin activate/deactivate <plugin name>"
plugin_storage = {}
+ reverse_lookup = {}
def __init__(self, actionqueue, queue="work"):
super(Plugins, self).__init__(actionqueue, queue)
def callback_plugins(self, ch, method, properties, body):
body = json.loads(body.decode("utf-8"))
logger.debug("received plugin in registry")
- self.plugin_storage[body["name"]] = body
+ self.plugin_storage[body["name"].lower()] = body
ch.basic_ack(delivery_tag=method.delivery_tag)
- def send_help(self, plugin_name=None):
+ def build_reverse_lookup(self):
+ reverse_lookup = {}
+ for plugin, definition in self.plugin_storage.items():
+ for key in definition['binding_keys']:
+ if key.startswith("nick"):
+ reverse_lookup[key.split('.')[1]] = plugin
+ def send_help(self, plugin_name=None):
if not plugin_name:
msg = "Known commands/reactions:\n" + ", ".join(self.plugin_storage.keys())
else:
- definition = self.plugin_storage[plugin_name]
+ definition = self.plugin_storage.get(plugin_name.lower()) \
+ or self.plugin_storage.get(self.reverse_lookup.get(plugin_name.lower()))
+ if not definition:
+ return Action(msg="unknown command, try help")
msg = ("{}: \n"
"Description:\t{}\n"
"Usage:\t{}\n\n").format(