Add a way to force success and force failure of a command permission check

(commands.py)
This commit is contained in:
jesopo 2019-01-28 23:29:52 +00:00
parent 5e12d87ca3
commit d10a6d94c1
3 changed files with 19 additions and 5 deletions

View file

@ -21,3 +21,5 @@ class Module(ModuleManager.BaseModule):
if not event["target"].mode_or_above(event["user"], if not event["target"].mode_or_above(event["user"],
require_mode): require_mode):
return "You do not have permission to do this" return "You do not have permission to do this"
else:
return utils.consts.PERMISSION_FORCE_SUCCESS

View file

@ -172,14 +172,22 @@ class Module(ModuleManager.BaseModule):
returns = self.events.on("preprocess.command").call_unsafe( returns = self.events.on("preprocess.command").call_unsafe(
hook=hook, user=event["user"], server=event["server"], hook=hook, user=event["user"], server=event["server"],
target=target, is_channel=is_channel, tags=event["tags"]) target=target, is_channel=is_channel, tags=event["tags"])
error = None
force_success
for returned in returns: for returned in returns:
if returned == False: if returned == utils.consts.PERMISSION_HARD_FAIL:
# denotes a "silent failure" # denotes a "silent failure"
target.buffer.skip_next() target.buffer.skip_next()
return return
if returned: elif returned == utils.consts.PERMISSION_FORCE_SUCCESS:
force_success = True
break
else:
# error message # error message
stderr.write(returned).send(command_method) error = returned
if error and not force_success:
stderr.write(error).send(command_method)
target.buffer.skip_next() target.buffer.skip_next()
return return

View file

@ -67,3 +67,7 @@ ANSI_BOLD = "\033[1m"
ANSI_BOLD_RESET = "\033[22m" ANSI_BOLD_RESET = "\033[22m"
ANSI_UNDERLINE = "\033[4m" ANSI_UNDERLINE = "\033[4m"
ANSI_UNDERLINE_RESET = "\033[24m" ANSI_UNDERLINE_RESET = "\033[24m"
PERMISSION_HARD_FAIL = 0
PERMISSION_FORCE_SUCCESS = 1
PERMISSION_ERROR = 2