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)
|
"%s %s" % (command, usage) for usage in usages)
|
||||||
return usage
|
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):
|
def _get_prefix(self, hook):
|
||||||
return hook.get_kwarg("prefix", None)
|
return hook.get_kwarg("prefix", None)
|
||||||
def _get_alias_of(self, hook):
|
def _get_alias_of(self, hook):
|
||||||
|
@ -266,29 +275,46 @@ class Module(ModuleManager.BaseModule):
|
||||||
:usage: [command]
|
:usage: [command]
|
||||||
"""
|
"""
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
command = event["args_split"][0].lower()
|
module_name = event["args_split"][0]
|
||||||
if command in self.events.on("received").on(
|
module = self.bot.modules.from_name(module_name)
|
||||||
"command").get_children():
|
if module == None:
|
||||||
hooks = self.events.on("received.command").on(command).get_hooks()
|
raise utils.EventError("No such module '%s'" % module_name)
|
||||||
help = self._get_help(hooks[0])
|
|
||||||
|
|
||||||
if help:
|
if len(event["args_split"]) == 1:
|
||||||
event["stdout"].write("%s: %s" % (command, help))
|
commands = []
|
||||||
else:
|
for command, command_hook in self._all_command_hooks().items():
|
||||||
event["stderr"].write("No help available for %s" % command)
|
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:
|
else:
|
||||||
event["stderr"].write("Unknown command '%s'" % command)
|
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" % (
|
||||||
|
requested_command, help))
|
||||||
|
else:
|
||||||
|
event["stderr"].write("No help available for %s" %
|
||||||
|
requested_command)
|
||||||
|
|
||||||
|
else:
|
||||||
|
event["stderr"].write("Unknown command '%s'" %
|
||||||
|
requested_command)
|
||||||
else:
|
else:
|
||||||
help_available = []
|
contexts = {}
|
||||||
for child in self.events.on("received.command").get_children():
|
for command, command_hook in self._all_command_hooks().items():
|
||||||
hooks = self.events.on("received.command").on(child).get_hooks()
|
if not command_hook.context in contexts:
|
||||||
|
module = self.bot.modules.from_context(command_hook.context)
|
||||||
|
contexts[module.context] = module.name
|
||||||
|
|
||||||
if hooks and self._get_help(hooks[0]
|
modules_available = sorted(contexts.values())
|
||||||
) and not self._get_alias_of(hooks[0]):
|
event["stdout"].write("Modules: %s" % ", ".join(modules_available))
|
||||||
help_available.append(child)
|
|
||||||
|
|
||||||
help_available = sorted(help_available)
|
|
||||||
event["stdout"].write("Commands: %s" % ", ".join(help_available))
|
|
||||||
|
|
||||||
@utils.hook("received.command.usage", min_args=1)
|
@utils.hook("received.command.usage", min_args=1)
|
||||||
def usage(self, event):
|
def usage(self, event):
|
||||||
|
|
Loading…
Reference in a new issue