Добавлен Middleware

This commit is contained in:
2025-06-23 09:49:24 +03:00
parent 8aa9c65fcc
commit 512eb9a4af
9 changed files with 253 additions and 49 deletions

View File

@@ -0,0 +1,41 @@
import asyncio
import logging
from typing import Any, Dict
from maxapi import Bot, Dispatcher
from maxapi.types import MessageCreated, Command, UpdateUnion
from maxapi.filters.middleware import BaseMiddleware
logging.basicConfig(level=logging.INFO)
bot = Bot(token='тут_ваш_токен')
dp = Dispatcher()
class CustomDataForRouterMiddleware(BaseMiddleware):
async def __call__(
self,
event: UpdateUnion,
data: Dict[str, Any]
):
data['custom_data'] = f'Это ID того кто вызвал команду: {event.from_user.user_id}'
return data
@dp.message_created(Command('custom_data'))
async def custom_data(event: MessageCreated, custom_data: str):
await event.message.answer(custom_data)
async def main():
dp.middlewares = [
CustomDataForRouterMiddleware()
]
await dp.start_polling(bot)
if __name__ == '__main__':
asyncio.run(main())