mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 18:35:28 +03:00
Initial commit
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from typing import Any, Callable
|
||||
from collections.abc import Awaitable
|
||||
from typing import Any, Callable
|
||||
|
||||
from aiogram import BaseMiddleware
|
||||
from aiogram.types import Message, TelegramObject
|
||||
from dishka import AsyncContainer
|
||||
|
||||
from trudex.infrastructure.database.repo import UserRepository
|
||||
from trudex.infrastructure.utils.config import Config
|
||||
|
||||
|
||||
class RejectNotAdminMiddleware(BaseMiddleware):
|
||||
@@ -23,15 +24,19 @@ class RejectNotAdminMiddleware(BaseMiddleware):
|
||||
container: AsyncContainer = data["dishka_container"]
|
||||
user_id = event.from_user.id
|
||||
admin_commands = ["/admin"]
|
||||
if event.text:
|
||||
if event.text.strip() in admin_commands:
|
||||
users_dao: UserRepository = await container.get(UserRepository)
|
||||
admins = await users_dao.get_admins()
|
||||
if user_id in [admin.id for admin in admins]:
|
||||
return await handler(event, data)
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
|
||||
if event.text and event.text.strip() in admin_commands:
|
||||
config: Config = await container.get(Config)
|
||||
|
||||
if user_id == config.bot.creator_id:
|
||||
return await handler(event, data)
|
||||
else:
|
||||
return await handler(event, data)
|
||||
|
||||
users_repo: UserRepository = await container.get(UserRepository)
|
||||
is_admin = await users_repo.is_admin(user_id)
|
||||
|
||||
if is_admin:
|
||||
return await handler(event, data)
|
||||
|
||||
return
|
||||
|
||||
return await handler(event, data)
|
||||
|
||||
Reference in New Issue
Block a user