Added changes annotation and update docs

This commit is contained in:
Alex Root Junior 2021-11-24 05:55:27 +02:00
parent 205c465c04
commit 8529f46b87
2 changed files with 33 additions and 1 deletions

13
CHANGES/759.feature Normal file
View file

@ -0,0 +1,13 @@
Added new custom operation for MagicFilter named :code:`as_`
Now you can use it to get magic filter result as handler argument
.. code-block:: python
from aiogram import F
...
@router.message(F.text.regexp(r"^(\d+)$").as_("digits"))
async def any_digits_handler(message: Message, digits: Match[str]):
await message.answer(html.quote(str(digits)))

View file

@ -16,7 +16,11 @@ That's mean you can install it and use with any other libraries and in own proje
Usage
=====
The **magic_filter** package implements class shortly named :class:`magic_filter.F` that's mean :code:`F` can be imported from :code:`magic_filter`. :class:`F` is alias for :class:`MagicFilter`.
The **magic_filter** package implements class shortly named :class:`magic_filter.F` that's mean :code:`F` can be imported from :code:`aiogram` or :code:`magic_filter`. :class:`F` is alias for :class:`MagicFilter`.
.. note::
Note that *aiogram* has an small extension over magic-filter and if you want to use this extension you should import magic from *aiogram* instead of *magic_filter* package
The :class:`MagicFilter` object is callable, supports :ref:`some actions <magic-filter-possible-actions>`
and memorize the attributes chain and the action which should be checked on demand.
@ -130,6 +134,21 @@ Can be used only with string attributes.
F.text.len() == 5 # lambda message: len(message.text) == 5
Get filter result as handler argument
-------------------------------------
This part is not available in *magic-filter* directly but can be used with *aiogram*
.. code-block:: python
from aiogram import F
...
@router.message(F.text.regexp(r"^(\d+)$").as_("digits"))
async def any_digits_handler(message: Message, digits: Match[str]):
await message.answer(html.quote(str(digits)))
Usage in *aiogram*
==================