|
|
|
@ -27,13 +27,21 @@ session = Session()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def auth(func): |
|
|
|
|
"""Аутентификация. |
|
|
|
|
|
|
|
|
|
Проверяем, что у юзера есть полномочия на выполнение действия - он |
|
|
|
|
должен быть в белом списке. |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
async def wrapper(message): |
|
|
|
|
users_list: Allowed_user = ( |
|
|
|
|
session.query(Allowed_user).order_by(Allowed_user.id).all() |
|
|
|
|
) |
|
|
|
|
finded_user: Allowed_user |
|
|
|
|
uid = message["from"]["id"] |
|
|
|
|
|
|
|
|
|
finded_user: Allowed_user = next( |
|
|
|
|
(u for u in users_list if u.user_id == message["from"]["id"]), None |
|
|
|
|
finded_user = ( |
|
|
|
|
session.query(Allowed_user) |
|
|
|
|
.filter(Allowed_user.user_id == uid) |
|
|
|
|
.one_or_none() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if not finded_user: |
|
|
|
@ -43,6 +51,20 @@ def auth(func):
|
|
|
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def only_admins(func): |
|
|
|
|
"""Действия только для админов.""" |
|
|
|
|
|
|
|
|
|
async def wrapper(message): |
|
|
|
|
uid = message["from"]["id"] |
|
|
|
|
|
|
|
|
|
if uid not in ADMINS: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
return await func(message) |
|
|
|
|
|
|
|
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def clean_up(message_id: int, delay_min: int): |
|
|
|
|
exp = datetime.now() + timedelta(minutes=delay_min) |
|
|
|
|
msg: Messages_to_delete = Messages_to_delete( |
|
|
|
|