diff options
| author | 2019-09-26 12:14:55 +0100 | |
|---|---|---|
| committer | 2019-09-26 12:14:55 +0100 | |
| commit | 2e80b223de84d93716baae2ba0ea1a0ec7070686 (patch) | |
| tree | 711b48e0877707322f504d73e72220acee62a34d | |
| parent | !echo should have a min_args kwarg (diff) | |
| signature | ||
allow all preprocess.command and check.command failures to have a message
| -rw-r--r-- | modules/channel_access.py | 5 | ||||
| -rw-r--r-- | modules/check_mode.py | 5 | ||||
| -rw-r--r-- | modules/commands/__init__.py | 36 | ||||
| -rw-r--r-- | modules/config.py | 3 | ||||
| -rw-r--r-- | modules/permissions/__init__.py | 15 | ||||
| -rw-r--r-- | modules/silence.py | 2 |
6 files changed, 40 insertions, 26 deletions
diff --git a/modules/channel_access.py b/modules/channel_access.py index a15f983e..100b22e0 100644 --- a/modules/channel_access.py +++ b/modules/channel_access.py @@ -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): diff --git a/modules/check_mode.py b/modules/check_mode.py index 67d48172..9fe3f464 100644 --- a/modules/check_mode.py +++ b/modules/check_mode.py @@ -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): diff --git a/modules/commands/__init__.py b/modules/commands/__init__.py index 601e8a3d..e01adb8b 100644 --- a/modules/commands/__init__.py +++ b/modules/commands/__init__.py @@ -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") diff --git a/modules/config.py b/modules/config.py index 50b0c904..97638a93 100644 --- a/modules/config.py +++ b/modules/config.py @@ -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) diff --git a/modules/permissions/__init__.py b/modules/permissions/__init__.py index ce259319..e36b51ad 100644 --- a/modules/permissions/__init__.py +++ b/modules/permissions/__init__.py @@ -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): diff --git a/modules/silence.py b/modules/silence.py index f4f6b32a..d1750814 100644 --- a/modules/silence.py +++ b/modules/silence.py @@ -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) |
