check "channel" coming from command_spec.py parsing (check_mode, channel_access)

This commit is contained in:
jesopo 2020-01-24 16:26:53 +00:00
parent f0d8853549
commit f51b06aae1
2 changed files with 17 additions and 16 deletions

View file

@ -13,21 +13,22 @@ class Module(ModuleManager.BaseModule):
return (require_access in access or "*" in access) and identified return (require_access in access or "*" in access) and identified
def _command_check(self, event, target, require_access): def _command_check(self, event, channel, require_access):
if event["is_channel"]: if channel and require_access:
if require_access: if self._has_channel_access(channel, event["user"],
if self._has_channel_access(target, event["user"], require_access):
require_access): return utils.consts.PERMISSION_FORCE_SUCCESS, None
return utils.consts.PERMISSION_FORCE_SUCCESS, None else:
else: return (utils.consts.PERMISSION_ERROR,
return (utils.consts.PERMISSION_ERROR,
"You do not have permission to do this") "You do not have permission to do this")
@utils.hook("preprocess.command") @utils.hook("preprocess.command")
def preprocess_command(self, event): def preprocess_command(self, event):
require_access = event["hook"].get_kwarg("require_access") require_access = event["hook"].get_kwarg("require_access")
if require_access: if require_access:
return self._command_check(event, event["target"], require_access) channel = event["kwargs"].get("channel",
event["target"] if event["is_channel"] else None)
return self._command_check(event, channel, require_access)
@utils.hook("check.command.channel-access") @utils.hook("check.command.channel-access")
def check_command(self, event): def check_command(self, event):

View file

@ -13,10 +13,10 @@ LOWHIGH = {
"Set which channel mode is considered to be 'high' access", example="o")) "Set which channel mode is considered to be 'high' access", example="o"))
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _check_command(self, event, channel, require_mode): def _check_command(self, event, channel, require_mode):
if event["is_channel"] and require_mode: print(channel)
if channel and require_mode:
if require_mode in LOWHIGH: if require_mode in LOWHIGH:
require_mode = event["target"].get_setting( require_mode = channel.get_setting("mode-%s" % require_mode,
"mode-%s" % require_mode,
LOWHIGH[require_mode]) LOWHIGH[require_mode])
elif require_mode == "admin": elif require_mode == "admin":
previous = None previous = None
@ -27,9 +27,7 @@ class Module(ModuleManager.BaseModule):
previous = mode previous = mode
elif require_mode == "highest": elif require_mode == "highest":
require_mode = event["server"].prefix_modes[0][0] require_mode = event["server"].prefix_modes[0][0]
if not channel.mode_or_above(event["user"], require_mode):
if not event["target"].mode_or_above(event["user"],
require_mode):
return (utils.consts.PERMISSION_ERROR, return (utils.consts.PERMISSION_ERROR,
"You do not have permission to do this") "You do not have permission to do this")
else: else:
@ -39,7 +37,9 @@ class Module(ModuleManager.BaseModule):
def preprocess_command(self, event): def preprocess_command(self, event):
require_mode = event["hook"].get_kwarg("require_mode") require_mode = event["hook"].get_kwarg("require_mode")
if not require_mode == None: if not require_mode == None:
return self._check_command(event, event["target"], require_mode) channel = event["kwargs"].get("channel",
event["target"] if event["is_channel"] else None)
return self._check_command(event, channel, require_mode)
@utils.hook("check.command.channel-mode") @utils.hook("check.command.channel-mode")
def check_command(self, event): def check_command(self, event):