Support a way to check user channel access in a private command
(channel_access.py)
This commit is contained in:
parent
bb84fc0291
commit
2071a10180
2 changed files with 20 additions and 6 deletions
|
@ -13,12 +13,25 @@ class Module(ModuleManager.BaseModule):
|
||||||
@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 event["is_channel"] and require_access:
|
if event["is_channel"]:
|
||||||
|
if require_access:
|
||||||
if self._has_channel_access(event["target"], event["user"],
|
if self._has_channel_access(event["target"], event["user"],
|
||||||
require_access):
|
require_access):
|
||||||
return utils.consts.PERMISSION_FORCE_SUCCESS
|
return utils.consts.PERMISSION_FORCE_SUCCESS
|
||||||
else:
|
else:
|
||||||
return "You do not have permission to do this"
|
return "You do not have permission to do this"
|
||||||
|
else:
|
||||||
|
channel_arg_index = event["hook"].get_kwarg("channel_arg")
|
||||||
|
channel_name = event["args_split"][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")
|
@utils.hook("get.haschannelaccess")
|
||||||
def has_channel_access(self, event):
|
def has_channel_access(self, event):
|
||||||
|
|
|
@ -171,7 +171,8 @@ 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"],
|
||||||
|
args_split=args_split)
|
||||||
|
|
||||||
hard_fail = False
|
hard_fail = False
|
||||||
force_success = False
|
force_success = False
|
||||||
|
|
Loading…
Reference in a new issue