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"],
|
||||
require_mode):
|
||||
return "You do not have permission to do this"
|
||||
else:
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
|
|
|
@ -172,14 +172,22 @@ 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)
|
||||
error = returned
|
||||
if error and not force_success:
|
||||
stderr.write(error).send(command_method)
|
||||
target.buffer.skip_next()
|
||||
return
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue