diff options
| author | 2018-09-26 15:58:16 +0100 | |
|---|---|---|
| committer | 2018-09-26 15:58:16 +0100 | |
| commit | ebc77fa5016a7f204779b0291ec2b6f1cc5596d4 (patch) | |
| tree | 0654655784c00bd5e7198f15d0cadff5d83f015e | |
| parent | Update where README.md says bot.db is (diff) | |
| signature | ||
Support using docstrings as command help
| -rw-r--r-- | modules/commands.py | 8 | ||||
| -rw-r--r-- | src/ModuleManager.py | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/modules/commands.py b/modules/commands.py index 02787791..74f70e1d 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -179,8 +179,12 @@ class Module(object): if command in self.events.on("received").on( "command").get_children(): hooks = self.events.on("received.command").on(command).get_hooks() - if hooks and "help" in hooks[0].kwargs: - event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"])) + kwargs = hooks[0].kwargs + help = hooks[0].kwargs.get("help", None + ) or hooks[0].function.__doc__ + + if help: + event["stdout"].write("%s: %s" % (command, help.strip())) else: event["stderr"].write("No help available for %s" % command) else: diff --git a/src/ModuleManager.py b/src/ModuleManager.py index 79ed8f2a..6f178a16 100644 --- a/src/ModuleManager.py +++ b/src/ModuleManager.py @@ -94,7 +94,7 @@ class ModuleManager(object): hooks = getattr(attribute, BITBOT_HOOKS_MAGIC) for hook in hooks: context_events.on(hook["event"]).hook(attribute, - **hook["kwargs"]) + docstring=attribute.__doc__, **hook["kwargs"]) module_object._context = context module_object._import_name = name |
