Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command filter now can be sets with BotCommand object #935

Merged
8 changes: 5 additions & 3 deletions aiogram/dispatcher/filters/builtin.py
Expand Up @@ -10,7 +10,7 @@

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]

Expand All @@ -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],
evgfilim1 marked this conversation as resolved.
Show resolved Hide resolved
prefixes: Union[Iterable, str] = '/',
ignore_case: bool = True,
ignore_mention: bool = False,
Expand Down Expand Up @@ -66,8 +66,10 @@ def __init__(self, commands: Union[Iterable, str],
@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):
evgfilim1 marked this conversation as resolved.
Show resolved Hide resolved
commands = (commands,)
if isinstance(commands, Iterable):
commands = [cmd.command if isinstance(cmd, BotCommand) else cmd for cmd in commands]
JrooTJunior marked this conversation as resolved.
Show resolved Hide resolved

self.commands = list(map(str.lower, commands)) if ignore_case else commands
self.prefixes = prefixes
Expand Down