diff options
| author | 2019-01-28 23:29:52 +0000 | |
|---|---|---|
| committer | 2019-01-28 23:29:52 +0000 | |
| commit | d10a6d94c13724f5c9ed476da63f0839ebaf2ad9 (patch) | |
| tree | d738a3564857654eb9214a012265f1a8055060ea /modules | |
| parent | Use `target` (after prefixes lstrip) to get channel object (line_handler.py) (diff) | |
| signature | ||
Add a way to force success and force failure of a command permission check
(commands.py)
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/check_mode.py | 2 | ||||
| -rw-r--r-- | modules/commands.py | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/modules/check_mode.py b/modules/check_mode.py index 4986752d..a33686d7 100644 --- a/modules/check_mode.py +++ b/modules/check_mode.py @@ -21,3 +21,5 @@ class Module(ModuleManager.BaseModule): if not event["target"].mode_or_above(event["user"], require_mode): return "You do not have permission to do this" + else: + return utils.consts.PERMISSION_FORCE_SUCCESS diff --git a/modules/commands.py b/modules/commands.py index dcd5abcc..53a288ad 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -172,16 +172,24 @@ class Module(ModuleManager.BaseModule): returns = self.events.on("preprocess.command").call_unsafe( hook=hook, user=event["user"], server=event["server"], target=target, is_channel=is_channel, tags=event["tags"]) + + error = None + force_success for returned in returns: - if returned == False: + if returned == utils.consts.PERMISSION_HARD_FAIL: # denotes a "silent failure" target.buffer.skip_next() return - if returned: + elif returned == utils.consts.PERMISSION_FORCE_SUCCESS: + force_success = True + break + else: # error message - stderr.write(returned).send(command_method) - target.buffer.skip_next() - return + error = returned + if error and not force_success: + stderr.write(error).send(command_method) + target.buffer.skip_next() + return if hook.kwargs.get("remove_empty", True): args_split = list(filter(None, args_split)) |
