aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2016-04-05 18:41:03 +0100
committerGravatar jesopo2016-04-05 18:41:03 +0100
commite8875ef17dd5cda8f4016d9bf6576d47eeeb99c5 (patch)
tree96430a89a69690034297961855f0f6d98bf99869
parentadded todo.py. (diff)
added a usage command to show usage help for commands.
-rw-r--r--modules/commands.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/commands.py b/modules/commands.py
index 1e376450..a274ce2a 100644
--- a/modules/commands.py
+++ b/modules/commands.py
@@ -47,7 +47,9 @@ class Module(object):
bot.events.on("received").on("message").on("private").hook(
self.private_message)
bot.events.on("received").on("command").on("help").hook(self.help,
- help="Show help on commands")
+ help="Show help for commands")
+ bot.events.on("received").on("command").on("usage").hook(self.usage,
+ help="Show usage help for commands", min_args=1)
bot.events.on("received").on("command").on("more").hook(self.more,
help="Get more output from the last command")
bot.events.on("new").on("user", "channel").hook(self.new)
@@ -147,6 +149,10 @@ class Module(object):
hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
if hooks and "help" in hooks[0].kwargs:
event["stdout"].write("%s: %s" % (command, hooks[0].kwargs["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.bot.events.on("received").on("command").get_children():
@@ -156,6 +162,18 @@ class Module(object):
help_available = sorted(help_available)
event["stdout"].write("Commands: %s" % ", ".join(help_available))
+ def usage(self, event):
+ command = event["args_split"][0].lower()
+ if command in self.bot.events.on("received").on(
+ "command").get_children():
+ hooks = self.bot.events.on("received").on("command").on(command).get_hooks()
+ if hooks and "usage" in hooks[0].kwargs:
+ event["stdout"].write("Usage: %s %s" % (command, hooks[0].kwargs["usage"]))
+ else:
+ event["stderr"].write("No usage help available for %s" % command)
+ else:
+ event["stderr"].write("Unknown command '%s'" % command)
+
def more(self, event):
if event["target"].last_stdout and event["target"].last_stdout.has_text():
event["target"].last_stdout.send()