diff --git a/docs/dispatcher/filters/chat_member_updated.rst b/docs/dispatcher/filters/chat_member_updated.rst index d6ba10c9..dd283171 100644 --- a/docs/dispatcher/filters/chat_member_updated.rst +++ b/docs/dispatcher/filters/chat_member_updated.rst @@ -86,10 +86,10 @@ Handle user leave or join events from aiogram.filters import IS_MEMBER, IS_NOT_MEMBER - @router.chat_member(member_status_changed=IS_MEMBER >> IS_NOT_MEMBER) + @router.chat_member(ChatMemberUpdatedFilter(member_status_changed=IS_MEMBER >> IS_NOT_MEMBER)) async def on_user_leave(event: ChatMemberUpdated): ... - @router.chat_member(member_status_changed=IS_NOT_MEMBER >> IS_MEMBER) + @router.chat_member(ChatMemberUpdatedFilter(member_status_changed=IS_NOT_MEMBER >> IS_MEMBER)) async def on_user_join(event: ChatMemberUpdated): ... Or construct your own terms via using pre-defined set of statuses and transitions. diff --git a/docs/dispatcher/filters/command.rst b/docs/dispatcher/filters/command.rst index ecded283..7281d751 100644 --- a/docs/dispatcher/filters/command.rst +++ b/docs/dispatcher/filters/command.rst @@ -21,8 +21,7 @@ Usage 1. Filter single variant of commands: :code:`Command(commands=["start"])` or :code:`Command(commands="start")` 2. Handle command by regexp pattern: :code:`Command(commands=[re.compile(r"item_(\d+)")])` 3. Match command by multiple variants: :code:`Command(commands=["item", re.compile(r"item_(\d+)")])` -4. Handle commands in public chats intended for other bots: :code:`Command(commands=["command"], commands)` -5. As keyword argument in registerer: :code:`@router.message(commands=["help"])` +4. Handle commands in public chats intended for other bots: :code:`Command(commands=["command"], commands_ignore_mention=True)` .. warning:: diff --git a/docs/dispatcher/filters/index.rst b/docs/dispatcher/filters/index.rst index e7507ba1..d9e56c75 100644 --- a/docs/dispatcher/filters/index.rst +++ b/docs/dispatcher/filters/index.rst @@ -2,6 +2,13 @@ Filtering events ================ + +.. danger:: + + Note that the design of filters will be changed in 3.0b5 + + `Read more >> `_ + Filters is needed for routing updates to the specific handler. Searching of handler is always stops on first match set of filters are pass. diff --git a/docs/dispatcher/filters/magic_data.rst b/docs/dispatcher/filters/magic_data.rst index 20336d17..86294a69 100644 --- a/docs/dispatcher/filters/magic_data.rst +++ b/docs/dispatcher/filters/magic_data.rst @@ -17,7 +17,7 @@ Or used from filters factory by passing corresponding arguments to handler regis Usage ===== -#. :code:`magic_data=F.event.from_user.id == F.config.admin_id` (Note that :code:`config` should be passed from middleware) +#. :code:`MagicData(magic_data=F.event.from_user.id == F.config.admin_id)` (Note that :code:`config` should be passed from middleware) Allowed handlers diff --git a/examples/echo_bot.py b/examples/echo_bot.py index 9097c7ac..29cf3b52 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -1,6 +1,7 @@ import logging from aiogram import Bot, Dispatcher, types +from aiogram.filters import Command from aiogram.types import Message TOKEN = "42:TOKEN" @@ -9,7 +10,7 @@ dp = Dispatcher() logger = logging.getLogger(__name__) -@dp.message(commands=["start"]) +@dp.message(Command(commands=["start"])) async def command_start_handler(message: Message) -> None: """ This handler receive messages with `/start` command diff --git a/examples/finite_state_machine.py b/examples/finite_state_machine.py index 197e8f66..8addfec0 100644 --- a/examples/finite_state_machine.py +++ b/examples/finite_state_machine.py @@ -5,6 +5,7 @@ from os import getenv from typing import Any, Dict from aiogram import Bot, Dispatcher, F, Router, html +from aiogram.filters import Command from aiogram.fsm.context import FSMContext from aiogram.fsm.state import State, StatesGroup from aiogram.types import KeyboardButton, Message, ReplyKeyboardMarkup, ReplyKeyboardRemove @@ -18,7 +19,7 @@ class Form(StatesGroup): language = State() -@form_router.message(commands=["start"]) +@form_router.message(Command(commands=["start"])) async def command_start(message: Message, state: FSMContext) -> None: await state.set_state(Form.name) await message.answer( @@ -27,7 +28,7 @@ async def command_start(message: Message, state: FSMContext) -> None: ) -@form_router.message(commands=["cancel"]) +@form_router.message(Command(commands=["cancel"])) @form_router.message(F.text.casefold() == "cancel") async def cancel_handler(message: Message, state: FSMContext) -> None: """ diff --git a/examples/specify_updates.py b/examples/specify_updates.py index 40e241bf..6a6abb65 100644 --- a/examples/specify_updates.py +++ b/examples/specify_updates.py @@ -1,6 +1,7 @@ import logging from aiogram import Bot, Dispatcher, Router +from aiogram.filters import Command from aiogram.types import ( CallbackQuery, ChatMemberUpdated, @@ -16,7 +17,7 @@ logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) -@dp.message(commands=["start"]) +@dp.message(Command(commands=["start"])) async def command_start_handler(message: Message) -> None: """ This handler receive messages with `/start` command @@ -71,7 +72,7 @@ async def my_chat_member_change(chat_member: ChatMemberUpdated, bot: Bot) -> Non def main() -> None: - # Initialize Bot instance with an default parse mode which will be passed to all API calls + # Initialize Bot instance with a default parse mode which will be passed to all API calls bot = Bot(TOKEN, parse_mode="HTML") sub_router.include_router(deep_dark_router)