summaryrefslogtreecommitdiff
path: root/helpers.py
diff options
context:
space:
mode:
authorDico200 <dico.karssiens@gmail.com>2015-03-25 00:38:56 +0100
committerDico200 <dico.karssiens@gmail.com>2015-03-25 00:38:56 +0100
commit75c9a86ba3f5a2ed454220c8d689a35d0454428f (patch)
tree697bd470c5c76fd3acef2b9f7a380a896a1c2498 /helpers.py
parentd160bbd91a3a56a35a5b90e174a7eb236c6ba92e (diff)
Replaced /sudo and /me with @simplecommand hook
Also improved simplecommand a little bit. Don't ask me why it doesn't work in its own file as I have no clue, it wasn't tracing the errors.
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/helpers.py b/helpers.py
index 83107a9..4357715 100644
--- a/helpers.py
+++ b/helpers.py
@@ -239,10 +239,13 @@ Information about some arguments:
- sender_limit: Defines what sendertype can use the command. Leave blank for console & player, 0 for player only, 1 for console only.
- min_args: The least arguments for the command.
- max_args: You guessed it right. Defaults to infinity (-1).
+- help_noargs: Whether to send help if no arguments are given
+- help_subcmd: Whether to send help upon '/<cmd> help'
*** DISCLAIMER ***
-Your command function must take four arguments: sender, command, label, args.
+Your command function must take four arguments: sender, command, label, args and help_msg.
+help_msg is a function which can be called like 'return help_msg(sender)' to send them information about the command.
Your function must also not return a boolean like before, but a String instead. The string returned will be sent to the player (&-codes supported).
Use None or "" for no message.
@@ -252,12 +255,10 @@ Feel free to edit or give suggestions (but don't break existing commands)
See below for an example command.
"""
-def simplecommand(cmd_name, aliases = [], permission = None, usage = None, description = None, sender_limit = -1, min_args = 0, max_args = -1):
+def simplecommand(cmd_name, aliases = [], permission = None, usage = "[args...]", description = None, sender_limit = -1, min_args = 0, max_args = -1, help_noargs = False, help_subcmd = False):
cmd_name = cmd_name.lower()
if not permission:
permission = "utils." + cmd_name
- if not usage:
- usage = "[args...]"
if not description:
description = "Handles " + cmd_name
@@ -278,9 +279,11 @@ def simplecommand(cmd_name, aliases = [], permission = None, usage = None, descr
return "&cThis command can only be run from the console" if isplayer else "&cThis command can only be run by players"
if not sender.hasPermission(permission):
return "&cYou do not have permission to use this command"
+ if ((not args) and help_noargs) or (help_subcmd and args and args[0].lower() == "help"):
+ return help_message(sender)
if not checkargs(sender, args, min_args, max_args):
return None
- return help_message(sender) if args and args[0].lower() == "help" else function(sender, command, label, args)
+ return function(sender, command, label, args, help_message)
return __call_func__
@@ -298,7 +301,7 @@ def simplecommand(cmd_name, aliases = [], permission = None, usage = None, descr
"""
try:
help_msg = "&aInformation about command /%s:\n &9%s" % (cmd_name, description.replace("\n", "\n "))
- help_msg += "\n\n&aSyntax: &o/%s %s" % (cmd_name, usage)
+ help_msg += "\n \n&aSyntax: /%s %s" % (cmd_name, usage)
if aliases:
help_msg += ("\n&6Aliases: " + "".join([(alias + ", ") for alias in aliases]))[:-2]
return help_msg