Add admin middleware

This commit is contained in:
Zakhar Izmaylov
2024-11-17 13:11:49 +03:00
parent 0c5d63c6e4
commit f585b82cd6
6 changed files with 43 additions and 6 deletions
+24
View File
@@ -0,0 +1,24 @@
from typing import Any, Awaitable, Callable, Dict
from aiogram import BaseMiddleware
from aiogram.types import TelegramObject
from config import ADMIN_ID
class AdminMiddleware(BaseMiddleware):
async def __call__(
self,
handler: Callable[[TelegramObject, Dict[str, Any]], Awaitable[Any]],
event: TelegramObject,
data: Dict[str, Any],
) -> Any:
if isinstance(ADMIN_ID, list):
if event.from_user.id in ADMIN_ID:
data["admin"] = True
elif isinstance(ADMIN_ID, int):
if event.from_user.id == ADMIN_ID:
data["admin"] = True
else:
data["admin"] = False
return await handler(event, data)