Init project
This commit is contained in:
19
birthday_pool_bot/telegram_bot/ui/middlewares/depends.py
Normal file
19
birthday_pool_bot/telegram_bot/ui/middlewares/depends.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from typing import Any, Awaitable, Callable
|
||||
|
||||
import aiogram
|
||||
from aiogram.types import TelegramObject
|
||||
|
||||
|
||||
class DependsMiddleware(aiogram.BaseMiddleware):
|
||||
def __init__(self, name: str, object_: Any):
|
||||
self._name = name
|
||||
self._object = object_
|
||||
|
||||
async def __call__(
|
||||
self,
|
||||
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
||||
event: TelegramObject,
|
||||
data: dict[str, Any],
|
||||
):
|
||||
data[self._name] = self._object
|
||||
return await handler(event, data)
|
||||
Reference in New Issue
Block a user