Actual 1.0.12 with changes

pull/1/head
hikari.ftg 2022-03-31 11:33:21 +00:00
parent 3d4be0b77b
commit 0d5ea045fd
4 changed files with 49 additions and 68 deletions

View File

@ -25,7 +25,7 @@ from .bot_interaction import BotInteractions
from .events import Events
from .token_obtainment import TokenObtainment
from typing import Union
from typing import Union, Callable
import inspect
from .. import security
@ -119,11 +119,11 @@ class InlineManager(Gallery, Form, BotInteractions, Events, TokenObtainment):
await asyncio.sleep(5)
def _find_caller_sec_map(self) -> Union[int, None]:
def _find_caller_sec_map(self) -> Union[Callable, None]:
try:
return next(
next(
self._db.get(security.__name__, "masks", {}).get(
lambda: self._db.get(security.__name__, "masks", {}).get(
f"{getattr(cls_, stack_entry.function).__module__}.{getattr(cls_, stack_entry.function).__name__}",
getattr(
getattr(cls_, stack_entry.function),

View File

@ -88,8 +88,7 @@ class Events(InlineUnit):
"""Checks if user is able to execute command with provided security mask"""
return await self._client.dispatcher.security._check(
message=message,
func=None,
mask=mask,
func=mask,
user=user,
)
@ -138,8 +137,8 @@ class Events(InlineUnit):
await self._check_inline_sec_by_mask(
mask=form.get(
"perms_map",
self._client.dispatcher.security._default,
),
lambda: self._client.dispatcher.security._default,
)(),
user=query.from_user.id,
message=form["message"],
)
@ -196,8 +195,22 @@ class Events(InlineUnit):
if query.data in self._custom_map:
if (
self._custom_map[query.data].get("force_me", False)
and query.from_user.id != self._me
and query.from_user.id not in self._client.dispatcher.security._owner
and query.from_user.id == self._me
) or (
await self._check_inline_sec_by_mask(
mask=self._custom_map[query.data].get(
"perms_map",
lambda: self._client.dispatcher.security._default,
)(),
user=query.from_user.id,
message=self._custom_map[query.data]["message"],
)
if "message" in self._custom_map[query.data]
else False
):
pass
elif (
query.from_user.id not in self._client.dispatcher.security._owner
and query.from_user.id
not in self._custom_map[query.data].get("always_allow", [])
):

View File

@ -45,7 +45,7 @@ class Gallery(InlineUnit):
next_handler: Union[FunctionType, List[str]],
caption: Union[str, FunctionType] = "",
*,
force_me: bool = True,
force_me: bool = False,
always_allow: Union[list, None] = None,
ttl: Union[int, bool] = False,
on_unload: Union[FunctionType, None] = None,
@ -168,6 +168,27 @@ class Gallery(InlineUnit):
**({"gif": gif} if gif else {}),
**({"always_allow": always_allow} if always_allow else {}),
**({"perms_map": perms_map} if perms_map else {}),
**({"message": message} if isinstance(message, Message) else {}),
}
default_map = {
**(
{"always_allow": self._galleries[gallery_uid]["always_allow"]}
if "always_allow" in self._galleries[gallery_uid]
else {}
),
**(
{"force_me": self._galleries[gallery_uid]["force_me"]}
if "force_me" in self._galleries[gallery_uid]
else {}
),
**(
{"ttl": self._galleries[gallery_uid]["ttl"]}
if "ttl" in self._galleries[gallery_uid]
else {}
),
**({"perms_map": perms_map} if perms_map else {}),
**({"message": message} if isinstance(message, Message) else {}),
}
self._custom_map[btn_call_data[0]] = {
@ -178,22 +199,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid,
)
),
**(
{"always_allow": self._galleries[gallery_uid]["always_allow"]}
if "always_allow" in self._galleries[gallery_uid]
else {}
),
**(
{"force_me": self._galleries[gallery_uid]["force_me"]}
if "force_me" in self._galleries[gallery_uid]
else {}
),
**(
{"ttl": self._galleries[gallery_uid]["ttl"]}
if "ttl" in self._galleries[gallery_uid]
else {}
),
**({"perms_map": perms_map} if perms_map else {}),
**default_map
}
self._custom_map[btn_call_data[1]] = {
@ -204,22 +210,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid,
)
),
**(
{"always_allow": self._galleries[gallery_uid]["always_allow"]}
if "always_allow" in self._galleries[gallery_uid]
else {}
),
**(
{"force_me": self._galleries[gallery_uid]["force_me"]}
if "force_me" in self._galleries[gallery_uid]
else {}
),
**(
{"ttl": self._galleries[gallery_uid]["ttl"]}
if "ttl" in self._galleries[gallery_uid]
else {}
),
**({"perms_map": perms_map} if perms_map else {}),
**default_map
}
self._custom_map[btn_call_data[2]] = {
@ -231,22 +222,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid,
)
),
**(
{"always_allow": self._galleries[gallery_uid]["always_allow"]}
if "always_allow" in self._galleries[gallery_uid]
else {}
),
**(
{"force_me": self._galleries[gallery_uid]["force_me"]}
if "force_me" in self._galleries[gallery_uid]
else {}
),
**(
{"ttl": self._galleries[gallery_uid]["ttl"]}
if "ttl" in self._galleries[gallery_uid]
else {}
),
**({"perms_map": perms_map} if perms_map else {}),
**default_map
}
if isinstance(message, Message):

View File

@ -186,21 +186,13 @@ class SecurityManager:
async def _check(
self,
message: Message,
func: FunctionType = None,
mask: int = None,
func: FunctionType,
user: int = None,
) -> bool:
"""Checks if message sender is permitted to execute certain function"""
if not func and not mask:
return False
self._reload_rights()
config = (
self.get_flags(func)
if func
else (mask & self._db.get(__name__, "bounding_mask", DEFAULT_PERMISSIONS))
)
config = self.get_flags(func)
if not config:
return False