Change prviate channel_access commands to use a "channel-access" yield check
This commit is contained in:
parent
f8b086b095
commit
229a45a491
2 changed files with 18 additions and 27 deletions
|
@ -13,34 +13,25 @@ class Module(ModuleManager.BaseModule):
|
|||
return ((require_access in access or "*" in access
|
||||
) and identified_account)
|
||||
|
||||
@utils.hook("preprocess.command")
|
||||
def preprocess_command(self, event):
|
||||
require_access = event["hook"].get_kwarg("require_access")
|
||||
def _command_check(self, event, target, require_access):
|
||||
if event["is_channel"]:
|
||||
if require_access:
|
||||
if self._has_channel_access(event["target"], event["user"],
|
||||
if self._has_channel_access(target, event["user"],
|
||||
require_access):
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
else:
|
||||
return "You do not have permission to do this"
|
||||
else:
|
||||
channel_arg_index = event["hook"].get_kwarg("channel_arg", None)
|
||||
if not channel_arg_index == None:
|
||||
channel_name = event["args_split"][int(channel_arg_index)]
|
||||
if channel_name in event["server"].channels:
|
||||
channel = event["server"].channels.get(channel_name)
|
||||
if self._has_channel_access(channel, event["user"],
|
||||
require_access):
|
||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||
else:
|
||||
return "You do not have permission to do this"
|
||||
else:
|
||||
return "I'm not in that channel"
|
||||
|
||||
@utils.hook("get.haschannelaccess")
|
||||
def has_channel_access(self, event):
|
||||
return self._has_channel_access(event["target"], event["user"],
|
||||
event["access"])
|
||||
@utils.hook("preprocess.command")
|
||||
def preprocess_command(self, event):
|
||||
require_access = event["hook"].get_kwarg("require_access")
|
||||
if require_access:
|
||||
return self._command_check(event, event["target"], require_access)
|
||||
|
||||
@utils.hook("check.command.channel-access")
|
||||
def check_command(self, event):
|
||||
return self._command_check(event, event["check_args"][0],
|
||||
event["check_args"][1])
|
||||
|
||||
@utils.hook("received.command.access", min_args=1, channel_only=True)
|
||||
def access(self, event):
|
||||
|
|
|
@ -53,11 +53,11 @@ class Module(ModuleManager.BaseModule):
|
|||
"""
|
||||
:help: Kick a user from the current channel
|
||||
:usage: <nickname> [reason]
|
||||
:require_access: kick
|
||||
:channel_arg: 0
|
||||
:prefix: Kick
|
||||
"""
|
||||
channel = event["server"].channels.get(event["args_split"][0])
|
||||
yield utils.Check("channel-access", channel, "kick")
|
||||
|
||||
self._kick_command(event, channel, event["args_split"][1:])
|
||||
|
||||
@utils.hook("received.command.k", alias_of="kick")
|
||||
|
@ -105,10 +105,10 @@ class Module(ModuleManager.BaseModule):
|
|||
"""
|
||||
:help: Ban a user/hostmask from the current channel
|
||||
:usage: <channel> <nickname/hostmask>
|
||||
:require_access: ban
|
||||
:channel_arg: 0
|
||||
"""
|
||||
channel = event["server"].channels.get(event["args_split"][0])
|
||||
yield utils.Check("channel-access", channel, "ban")
|
||||
|
||||
self._ban(event["server"], channel, True, event["args_split"][1])
|
||||
@utils.hook("received.command.ban", channel_only=True, min_args=1)
|
||||
def ban(self, event):
|
||||
|
@ -179,10 +179,10 @@ class Module(ModuleManager.BaseModule):
|
|||
"""
|
||||
:help: Unban a user/hostmask from the current channel
|
||||
:usage: <channel> <nickname/hostmask>
|
||||
:require_access: ban
|
||||
:channel_arg: 0
|
||||
"""
|
||||
channel = event["server"].channels.get(event["args_split"][0])
|
||||
yield utils.Check("channel-access", channel, "ban")
|
||||
|
||||
self._ban(event["server"], channel, False, event["args_split"][1])
|
||||
|
||||
@utils.hook("received.command.unban", channel_only=True, min_args=1)
|
||||
|
|
Loading…
Reference in a new issue