Actually add tsec nonick...

pull/1/head
hikariatama 2023-05-21 17:55:23 +00:00
parent 429ee48118
commit 5272347374
2 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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],