Add a way to force success and force failure of a command permission check
(commands.py)
This commit is contained in:
parent
5e12d87ca3
commit
d10a6d94c1
3 changed files with 19 additions and 5 deletions
|
@ -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
|
||||||
|
|
|
@ -172,16 +172,24 @@ 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
|
||||||
target.buffer.skip_next()
|
if error and not force_success:
|
||||||
return
|
stderr.write(error).send(command_method)
|
||||||
|
target.buffer.skip_next()
|
||||||
|
return
|
||||||
|
|
||||||
if hook.kwargs.get("remove_empty", True):
|
if hook.kwargs.get("remove_empty", True):
|
||||||
args_split = list(filter(None, args_split))
|
args_split = list(filter(None, args_split))
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue