]> git.aero2k.de Git - urlbot-v3.git/commitdiff
enable reverse lookup of commands to plugin names for help
authorThorsten <mail@aero2k.de>
Thu, 4 Oct 2018 17:53:10 +0000 (19:53 +0200)
committerThorsten <mail@aero2k.de>
Thu, 4 Oct 2018 17:53:10 +0000 (19:53 +0200)
distbot/plugins/plugin_help.py [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index ae650e1..ce52450
@@ -31,6 +31,7 @@ class Plugins(Worker):
     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)
@@ -46,15 +47,24 @@ class Plugins(Worker):
     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(