Przeglądaj źródła

Implement help messages as docstrings

Kirk Trombley 4 lat temu
rodzic
commit
d9fed2185b
1 zmienionych plików z 14 dodań i 0 usunięć
  1. 14 0
      lib/rollbot/bot.py

+ 14 - 0
lib/rollbot/bot.py

@@ -52,6 +52,20 @@ class Rollbot(Generic[RawMsg]):
             return
 
         command = self.command_config.aliases.get(message.command.name, message.command.name)
+
+        if command == "help":
+            args = message.command.args.split(maxsplit=1)
+            if len(args) == 0:
+                help_msg = "Use this command to look up the help info of another command, try !help roll for example!"
+            else:
+                cmd = self.command_config.commands.get(args[0], None)
+                if cmd is None or cmd.__doc__ is None:
+                    help_msg = "Sorry! I don't have any explanation of that command"
+                else:
+                    help_msg = cmd.__doc__.strip()
+            await self.respond(Response.from_message(message, help_msg))
+            return
+
         res = self.command_config.call_and_response.get(command, None)
         if res is not None:
             await self.respond(Response.from_message(message, res))