From 23568d647daef107d76eeeac2d5cfe79c291de1e Mon Sep 17 00:00:00 2001 From: Yuriy Chebyshev Date: Fri, 24 Jun 2022 13:30:49 +0300 Subject: [PATCH] command filter now can be sets with BotCommand object instead of or together with plain strings --- aiogram/dispatcher/filters/builtin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aiogram/dispatcher/filters/builtin.py b/aiogram/dispatcher/filters/builtin.py index 373dafe5..2231f96f 100644 --- a/aiogram/dispatcher/filters/builtin.py +++ b/aiogram/dispatcher/filters/builtin.py @@ -10,7 +10,7 @@ from babel.support import LazyProxy from aiogram import types from aiogram.dispatcher.filters.filters import BoundFilter, Filter -from aiogram.types import CallbackQuery, ChatType, InlineQuery, Message, Poll, ChatMemberUpdated +from aiogram.types import CallbackQuery, ChatType, InlineQuery, Message, Poll, ChatMemberUpdated, BotCommand ChatIDArgumentType = typing.Union[typing.Iterable[typing.Union[int, str]], str, int] @@ -34,7 +34,7 @@ class Command(Filter): By default this filter is registered for messages and edited messages handlers. """ - def __init__(self, commands: Union[Iterable, str], + def __init__(self, commands: Union[Iterable[str], Iterable[BotCommand], str, BotCommand], prefixes: Union[Iterable, str] = '/', ignore_case: bool = True, ignore_mention: bool = False, @@ -66,8 +66,10 @@ class Command(Filter): @dp.message_handler(commands=['myCommand'], commands_ignore_caption=False, content_types=ContentType.ANY) @dp.message_handler(Command(['myCommand'], ignore_caption=False), content_types=[ContentType.TEXT, ContentType.DOCUMENT]) """ - if isinstance(commands, str): + if isinstance(commands, str) or isinstance(commands, BotCommand): commands = (commands,) + if isinstance(commands, Iterable): + commands = [cmd.command if isinstance(cmd, BotCommand) else cmd for cmd in commands] self.commands = list(map(str.lower, commands)) if ignore_case else commands self.prefixes = prefixes