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 .events import Events
from .token_obtainment import TokenObtainment from .token_obtainment import TokenObtainment
from typing import Union from typing import Union, Callable
import inspect import inspect
from .. import security from .. import security
@ -119,11 +119,11 @@ class InlineManager(Gallery, Form, BotInteractions, Events, TokenObtainment):
await asyncio.sleep(5) await asyncio.sleep(5)
def _find_caller_sec_map(self) -> Union[int, None]: def _find_caller_sec_map(self) -> Union[Callable, None]:
try: try:
return next( return next(
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__}", f"{getattr(cls_, stack_entry.function).__module__}.{getattr(cls_, stack_entry.function).__name__}",
getattr( getattr(
getattr(cls_, stack_entry.function), 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""" """Checks if user is able to execute command with provided security mask"""
return await self._client.dispatcher.security._check( return await self._client.dispatcher.security._check(
message=message, message=message,
func=None, func=mask,
mask=mask,
user=user, user=user,
) )
@ -138,8 +137,8 @@ class Events(InlineUnit):
await self._check_inline_sec_by_mask( await self._check_inline_sec_by_mask(
mask=form.get( mask=form.get(
"perms_map", "perms_map",
self._client.dispatcher.security._default, lambda: self._client.dispatcher.security._default,
), )(),
user=query.from_user.id, user=query.from_user.id,
message=form["message"], message=form["message"],
) )
@ -196,8 +195,22 @@ class Events(InlineUnit):
if query.data in self._custom_map: if query.data in self._custom_map:
if ( if (
self._custom_map[query.data].get("force_me", False) self._custom_map[query.data].get("force_me", False)
and query.from_user.id != self._me and query.from_user.id == self._me
and query.from_user.id not in self._client.dispatcher.security._owner ) 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 and query.from_user.id
not in self._custom_map[query.data].get("always_allow", []) 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]], next_handler: Union[FunctionType, List[str]],
caption: Union[str, FunctionType] = "", caption: Union[str, FunctionType] = "",
*, *,
force_me: bool = True, force_me: bool = False,
always_allow: Union[list, None] = None, always_allow: Union[list, None] = None,
ttl: Union[int, bool] = False, ttl: Union[int, bool] = False,
on_unload: Union[FunctionType, None] = None, on_unload: Union[FunctionType, None] = None,
@ -168,6 +168,27 @@ class Gallery(InlineUnit):
**({"gif": gif} if gif else {}), **({"gif": gif} if gif else {}),
**({"always_allow": always_allow} if always_allow else {}), **({"always_allow": always_allow} if always_allow else {}),
**({"perms_map": perms_map} if perms_map 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]] = { self._custom_map[btn_call_data[0]] = {
@ -178,22 +199,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid, gallery_uid=gallery_uid,
) )
), ),
**( **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 {}),
} }
self._custom_map[btn_call_data[1]] = { self._custom_map[btn_call_data[1]] = {
@ -204,22 +210,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid, gallery_uid=gallery_uid,
) )
), ),
**( **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 {}),
} }
self._custom_map[btn_call_data[2]] = { self._custom_map[btn_call_data[2]] = {
@ -231,22 +222,7 @@ class Gallery(InlineUnit):
gallery_uid=gallery_uid, gallery_uid=gallery_uid,
) )
), ),
**( **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 {}),
} }
if isinstance(message, Message): if isinstance(message, Message):

View File

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