allow all preprocess.command and check.command failures to have a message
This commit is contained in:
parent
1da8e15b78
commit
2e80b223de
6 changed files with 40 additions and 26 deletions
|
@ -18,9 +18,10 @@ class Module(ModuleManager.BaseModule):
|
|||
if require_access:
|
||||
if self._has_channel_access(target, event["user"],
|
||||
require_access):
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
else:
|
||||
return "You do not have permission to do this"
|
||||
return (utils.consts.PERMISSION_ERROR,
|
||||
"You do not have permission to do this")
|
||||
|
||||
@utils.hook("preprocess.command")
|
||||
def preprocess_command(self, event):
|
||||
|
|
|
@ -21,9 +21,10 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
if not event["target"].mode_or_above(event["user"],
|
||||
require_mode):
|
||||
return "You do not have permission to do this"
|
||||
return (utils.consts.PERMISSION_ERROR,
|
||||
"You do not have permission to do this")
|
||||
else:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
|
||||
@utils.hook("preprocess.command")
|
||||
def preprocess_command(self, event):
|
||||
|
|
|
@ -141,16 +141,20 @@ class Module(ModuleManager.BaseModule):
|
|||
force_success = False
|
||||
error = None
|
||||
for returned in returns:
|
||||
if returned == utils.consts.PERMISSION_HARD_FAIL:
|
||||
hard_fail = True
|
||||
break
|
||||
elif returned == utils.consts.PERMISSION_FORCE_SUCCESS:
|
||||
force_success = True
|
||||
elif returned:
|
||||
error = returned
|
||||
if returned:
|
||||
type, message = returned
|
||||
if type == utils.consts.PERMISSION_HARD_FAIL:
|
||||
error = message
|
||||
hard_fail = True
|
||||
break
|
||||
elif type == utils.consts.PERMISSION_FORCE_SUCCESS:
|
||||
force_success = True
|
||||
break
|
||||
elif type == utils.consts.PERMISSION_ERROR:
|
||||
error = returned
|
||||
|
||||
if hard_fail:
|
||||
return False, None
|
||||
return False, error
|
||||
elif not force_success and error:
|
||||
return False, error
|
||||
else:
|
||||
|
@ -242,10 +246,12 @@ class Module(ModuleManager.BaseModule):
|
|||
if min_args and len(event["args_split"]) < min_args:
|
||||
usage = self._get_usage(event["hook"], event["command"],
|
||||
event["command_prefix"])
|
||||
error = None
|
||||
if usage:
|
||||
return "Not enough arguments, usage: %s" % usage
|
||||
error = "Not enough arguments, usage: %s" % usage
|
||||
else:
|
||||
return "Not enough arguments (minimum: %d)" % min_args
|
||||
error = "Not enough arguments (minimum: %d)" % min_args
|
||||
return utils.consts.PERMISSION_HARD_FAIL, error
|
||||
|
||||
def _command_prefix(self, server, channel):
|
||||
return channel.get_setting("command-prefix",
|
||||
|
@ -429,13 +435,15 @@ class Module(ModuleManager.BaseModule):
|
|||
def check_command_self(self, event):
|
||||
if event["server"].irc_lower(event["request_args"][0]
|
||||
) == event["user"].name:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
else:
|
||||
return "You do not have permission to do this"
|
||||
return (utils.consts.PERMISSION_ERROR,
|
||||
"You do not have permission to do this")
|
||||
|
||||
@utils.hook("check.command.is-channel")
|
||||
def check_command_is_channel(self, event):
|
||||
if event["is_channel"]:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
else:
|
||||
return "This command can only be used in-channel"
|
||||
return (utils.consts.PERMISSION_ERROR,
|
||||
"This command can only be used in-channel")
|
||||
|
|
|
@ -102,9 +102,10 @@ class Module(ModuleManager.BaseModule):
|
|||
else:
|
||||
context = context[0]
|
||||
|
||||
return "Please set %s, e.g.: %sconfig %s %s %s" % (
|
||||
error = "Please set %s, e.g.: %sconfig %s %s %s" % (
|
||||
require_setting, event["command_prefix"], context,
|
||||
require_setting, example)
|
||||
return utils.consts.PERMISSION_ERROR, error
|
||||
|
||||
def _get_export_setting(self, context):
|
||||
settings = self.exports.get_all(context)
|
||||
|
|
|
@ -192,7 +192,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
def _check_command(self, event, permission, authenticated):
|
||||
if event["user"].admin_master:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
|
||||
identity_mechanism = event["server"].get_setting("identity-mechanism",
|
||||
"internal")
|
||||
|
@ -213,18 +213,21 @@ class Module(ModuleManager.BaseModule):
|
|||
has_permission = permission and (
|
||||
permission in permissions or "*" in permissions)
|
||||
if not identified_account or not has_permission:
|
||||
return "You do not have permission to do that"
|
||||
return (utils.consts.PERMISSION_ERROR,
|
||||
"You do not have permission to do that")
|
||||
else:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
elif authenticated:
|
||||
if not identified_account:
|
||||
error = None
|
||||
if identity_mechanism == "internal":
|
||||
return REQUIRES_IDENTIFY_INTERNAL % (
|
||||
error = REQUIRES_IDENTIFY_INTERNAL % (
|
||||
event["server"].nickname, event["server"].nickname)
|
||||
else:
|
||||
return REQUIRES_IDENTIFY
|
||||
error = REQUIRES_IDENTIFY
|
||||
return utils.consts.PERMISSION_ERROR, error
|
||||
else:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS, None
|
||||
|
||||
@utils.hook("preprocess.command")
|
||||
def preprocess_command(self, event):
|
||||
|
|
|
@ -57,7 +57,7 @@ class Module(ModuleManager.BaseModule):
|
|||
silence_until = event["target"].get_setting("silence-until", None)
|
||||
if silence_until:
|
||||
if self._is_silenced(event["target"]):
|
||||
return utils.consts.PERMISSION_HARD_FAIL
|
||||
return utils.consts.PERMISSION_HARD_FAIL, None
|
||||
|
||||
@utils.hook("unknown.command")
|
||||
@utils.kwarg("priority", EventManager.PRIORITY_HIGH)
|
||||
|
|
Loading…
Reference in a new issue