From 5272347374ee70ffe04a3244d347c392d625dd13 Mon Sep 17 00:00:00 2001 From: hikariatama Date: Sun, 21 May 2023 17:55:23 +0000 Subject: [PATCH] Actually add tsec nonick... --- hikka/dispatcher.py | 5 ++++- hikka/security.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hikka/dispatcher.py b/hikka/dispatcher.py index 2a75563..a42ed12 100755 --- a/hikka/dispatcher.py +++ b/hikka/dispatcher.py @@ -359,6 +359,7 @@ class CommandDispatcher: and not self._db.get(main.__name__, "no_nickname", False) and command not in self._db.get(main.__name__, "nonickcmds", []) and initiator not in self._db.get(main.__name__, "nonickusers", []) + and not self.security.check_tsec(initiator, command) and utils.get_chat_id(event) not in self._db.get(main.__name__, "nonickchats", []) ): @@ -370,7 +371,9 @@ class CommandDispatcher: not func or not await self._handle_ratelimit(message, func) or not await self.security.check( - message, func, usernames=self._cached_usernames + message, + func, + usernames=self._cached_usernames, ) ): return False diff --git a/hikka/security.py b/hikka/security.py index bd49e01..1f81712 100755 --- a/hikka/security.py +++ b/hikka/security.py @@ -334,6 +334,29 @@ class SecurityManager: for rule in self._tsec_user ) + def check_tsec(self, user_id: int, command: str) -> bool: + for info in self._sgroups.copy().values(): + if user_id in info.users: + for permission in info.permissions: + if ( + permission["rule_type"] == "command" + and permission["rule"] == command + or permission["rule_type"] == "module" + and permission["rule"] == command + ): + return True + + for info in self._tsec_user.copy(): + if info["target"] == user_id and ( + info["rule_type"] == "command" + and info["rule"] == command + or info["rule_type"] == "module" + and command in self._client.loader.commands + and info["rule"] + == self._client.loader.commands[command].__qualname__.split(".")[0] + ): + return True + async def check( self, message: typing.Optional[Message],