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( if command in self.events.on("received").on(
"command").get_children(): "command").get_children():
hooks = self.events.on("received.command").on(command).get_hooks() hooks = self.events.on("received.command").on(command).get_hooks()
if hooks and "help" in hooks[0].kwargs: kwargs = hooks[0].kwargs
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["help"])) help = hooks[0].kwargs.get("help", None
) or hooks[0].function.__doc__
if help:
event["stdout"].write("%s: %s" % (command, help.strip()))
else: else:
event["stderr"].write("No help available for %s" % command) event["stderr"].write("No help available for %s" % command)
else: else:

View file

@ -94,7 +94,7 @@ class ModuleManager(object):
hooks = getattr(attribute, BITBOT_HOOKS_MAGIC) hooks = getattr(attribute, BITBOT_HOOKS_MAGIC)
for hook in hooks: for hook in hooks:
context_events.on(hook["event"]).hook(attribute, context_events.on(hook["event"]).hook(attribute,
**hook["kwargs"]) docstring=attribute.__doc__, **hook["kwargs"])
module_object._context = context module_object._context = context
module_object._import_name = name module_object._import_name = name