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)
This commit is contained in:
jesopo 2019-01-29 15:33:55 +00:00
parent bdeaf7b69e
commit e0722dfc8a

View file

@ -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):
"""