Support using docstrings as command help

This commit is contained in:
jesopo 2018-09-26 15:58:16 +01:00
parent 3f2e5ca712
commit ebc77fa501
2 changed files with 7 additions and 3 deletions

View file

@ -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:

View file

@ -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