mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
command filter now can be sets with BotCommand object instead of or together with plain strings
This commit is contained in:
parent
df23d4fd59
commit
23568d647d
1 changed files with 5 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue