diff --git a/src/bot/handlers/utils/registry/__init__.py b/src/bot/handlers/utils/registry/__init__.py index 81be9e3..af8a346 100644 --- a/src/bot/handlers/utils/registry/__init__.py +++ b/src/bot/handlers/utils/registry/__init__.py @@ -1,9 +1,9 @@ __all__ = ["RouterRegistry"] -from typing import Any, Callable, Optional, Union +from typing import Any, Callable, Union -from aiogram import Bot, Router +from aiogram import Bot, F, Router from aiogram.filters import BaseFilter, Command from aiogram.types.bot_command import BotCommand from aiogram.types.bot_command_scope_all_private_chats import ( @@ -33,7 +33,8 @@ class RouterRegistry: description: str, chat_types: Union[ChatType, list[ChatType]], filters: Union[BaseFilter, list[BaseFilter]] = [], - command: Optional[str] = None, + command: str, + is_callback: bool = False, ) -> Callable[[Any], HandlerType]: if isinstance(chat_types, ChatType): chat_types = [chat_types] @@ -50,11 +51,12 @@ class RouterRegistry: ) self._handlers.append(meta) - if command is None: + if is_callback: self._router.callback_query.register( func, *filters, ChatTypeFilter(chat_types=chat_types), + F.data == command, ) else: self._router.message.register( diff --git a/src/bot/handlers/utils/types/handler.py b/src/bot/handlers/utils/types/handler.py index 1304752..67e6fa8 100644 --- a/src/bot/handlers/utils/types/handler.py +++ b/src/bot/handlers/utils/types/handler.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Any, Awaitable, Callable, Optional, TypeVar +from typing import Any, Awaitable, Callable, TypeVar from bot.handlers.utils.types import ChatType @@ -13,4 +13,5 @@ class HandlerMeta: func: Callable[[Any], Awaitable[Any]] description: str chat_types: list[ChatType] - command: Optional[str] = None + command: str + is_callback: bool = False