Change !help to be !help <module> <command>
This commit is contained in:
parent
091818fa32
commit
81bb0242fe
1 changed files with 45 additions and 19 deletions
|
@ -254,6 +254,15 @@ class Module(ModuleManager.BaseModule):
|
|||
"%s %s" % (command, usage) for usage in usages)
|
||||
return usage
|
||||
|
||||
def _all_command_hooks(self):
|
||||
all_hooks = {}
|
||||
for child_name in self.events.on("received.command").get_children():
|
||||
hooks = self.events.on("received.command").on(child_name
|
||||
).get_hooks()
|
||||
if hooks:
|
||||
all_hooks[child_name.lower()] = hooks[0]
|
||||
return all_hooks
|
||||
|
||||
def _get_prefix(self, hook):
|
||||
return hook.get_kwarg("prefix", None)
|
||||
def _get_alias_of(self, hook):
|
||||
|
@ -266,29 +275,46 @@ class Module(ModuleManager.BaseModule):
|
|||
:usage: [command]
|
||||
"""
|
||||
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()
|
||||
help = self._get_help(hooks[0])
|
||||
module_name = event["args_split"][0]
|
||||
module = self.bot.modules.from_name(module_name)
|
||||
if module == None:
|
||||
raise utils.EventError("No such module '%s'" % module_name)
|
||||
|
||||
if len(event["args_split"]) == 1:
|
||||
commands = []
|
||||
for command, command_hook in self._all_command_hooks().items():
|
||||
if (command_hook.context == module.context and
|
||||
not self._get_alias_of(command_hook)):
|
||||
commands.append(command)
|
||||
|
||||
event["stdout"].write("Commands for %s module: %s" % (
|
||||
module.name, ", ".join(commands)))
|
||||
else:
|
||||
requested_command = event["args_split"][1].lower()
|
||||
available_commands = self._all_command_hooks()
|
||||
if requested_command in available_commands:
|
||||
command_hook = available_commands[requested_command]
|
||||
help = self._get_help(command_hook)
|
||||
|
||||
if help:
|
||||
event["stdout"].write("%s: %s" % (command, help))
|
||||
event["stdout"].write("%s: %s" % (
|
||||
requested_command, help))
|
||||
else:
|
||||
event["stderr"].write("No help available for %s" % command)
|
||||
else:
|
||||
event["stderr"].write("Unknown command '%s'" % command)
|
||||
else:
|
||||
help_available = []
|
||||
for child in self.events.on("received.command").get_children():
|
||||
hooks = self.events.on("received.command").on(child).get_hooks()
|
||||
event["stderr"].write("No help available for %s" %
|
||||
requested_command)
|
||||
|
||||
if hooks and self._get_help(hooks[0]
|
||||
) and not self._get_alias_of(hooks[0]):
|
||||
help_available.append(child)
|
||||
else:
|
||||
event["stderr"].write("Unknown command '%s'" %
|
||||
requested_command)
|
||||
else:
|
||||
contexts = {}
|
||||
for command, command_hook in self._all_command_hooks().items():
|
||||
if not command_hook.context in contexts:
|
||||
module = self.bot.modules.from_context(command_hook.context)
|
||||
contexts[module.context] = module.name
|
||||
|
||||
help_available = sorted(help_available)
|
||||
event["stdout"].write("Commands: %s" % ", ".join(help_available))
|
||||
modules_available = sorted(contexts.values())
|
||||
event["stdout"].write("Modules: %s" % ", ".join(modules_available))
|
||||
|
||||
@utils.hook("received.command.usage", min_args=1)
|
||||
def usage(self, event):
|
||||
|
|
Loading…
Reference in a new issue