From 4d41848b578f3fe3cb51012b80d0dea13f24331a Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 26 Sep 2018 18:26:10 +0100 Subject: Also use docstrings to check if a command has help available, allow one-string denotation of multiple event hooks --- modules/commands.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/commands.py b/modules/commands.py index 74f70e1d..a58d0748 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -173,15 +173,16 @@ class Module(object): command = event["message_split"][0].lower() self.message(event, command) + def _get_help(self, hook): + return hook.kwargs.get("help", None) or hook.function.__doc__ + def help(self, event): if event["args"]: command = event["args_split"][0].lower() if command in self.events.on("received").on( "command").get_children(): hooks = self.events.on("received.command").on(command).get_hooks() - kwargs = hooks[0].kwargs - help = hooks[0].kwargs.get("help", None - ) or hooks[0].function.__doc__ + help = self._get_help(hooks[0]) if help: event["stdout"].write("%s: %s" % (command, help.strip())) @@ -193,7 +194,8 @@ class Module(object): help_available = [] for child in self.events.on("received.command").get_children(): hooks = self.events.on("received.command").on(child).get_hooks() - if hooks and "help" in hooks[0].kwargs: + + if hooks and self._get_help(hooks[0]): help_available.append(child) help_available = sorted(help_available) event["stdout"].write("Commands: %s" % ", ".join(help_available)) -- cgit v1.3.1-10-gc9f91