From d10a6d94c13724f5c9ed476da63f0839ebaf2ad9 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 28 Jan 2019 23:29:52 +0000 Subject: [PATCH] Add a way to force success and force failure of a command permission check (commands.py) --- modules/check_mode.py | 2 ++ modules/commands.py | 18 +++++++++++++----- src/utils/consts.py | 4 ++++ 3 files changed, 19 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)) diff --git a/src/utils/consts.py b/src/utils/consts.py index 81e86626..f5272cab 100644 --- a/src/utils/consts.py +++ b/src/utils/consts.py @@ -67,3 +67,7 @@ ANSI_BOLD = "\033[1m" ANSI_BOLD_RESET = "\033[22m" ANSI_UNDERLINE = "\033[4m" ANSI_UNDERLINE_RESET = "\033[24m" + +PERMISSION_HARD_FAIL = 0 +PERMISSION_FORCE_SUCCESS = 1 +PERMISSION_ERROR = 2