aboutsummaryrefslogtreecommitdiff
path: root/modules/channel_access.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-01-29 15:33:55 +0000
committerGravatar jesopo2019-01-29 15:33:55 +0000
commite0722dfc8a9dfce406dfd89fc4e0f98fa03b1ac8 (patch)
treeae8c88f1db89cd96e7c5095098edc962a6c75597 /modules/channel_access.py
parentAdd clarification to the top of bot.conf.example about leaving settings blank or (diff)
signature
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)
Diffstat (limited to 'modules/channel_access.py')
-rw-r--r--modules/channel_access.py21
1 files 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):
"""