From e0722dfc8a9dfce406dfd89fc4e0f98fa03b1ac8 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 29 Jan 2019 15:33:55 +0000 Subject: Seperate out access checking logic so we can call across-modules with the event system to check if users have specific channel access (channel_access.py) --- modules/channel_access.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/channel_access.py b/modules/channel_access.py index ee54b50d..0c5e07da 100644 --- a/modules/channel_access.py +++ b/modules/channel_access.py @@ -3,20 +3,29 @@ from src import ModuleManager, utils class Module(ModuleManager.BaseModule): _name = "ChanAccess" + def _has_channel_access(self, target, user, require_access): + access = event["target"].get_user_setting(event["user"].get_id(), + "access", []) + identified_account = event["user"].get_identified_account() + + 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") if event["is_channel"] and require_access: - access = event["target"].get_user_setting(event["user"].get_id(), - "access", []) - identified_account = event["user"].get_identified_account() - - if ((require_access in access or "*" in access) and - identified_account): + if self._has_channel_access(event["target"], event["user"], + require_access): return utils.consts.PERMISSION_FORCE_SUCCESS else: return "You do not have permission to do this" + @utils.hook("get.haschannelaccess") + def has_channel_access(self, event): + return self._has_channel_access(event["target"], event["user"], + event["access"]) + @utils.hook("received.command.access", min_args=1, channel_only=True) def access(self, event): """ -- cgit v1.3.1-10-gc9f91