Extended MagicFilter with aiogram-specific operation (#759)

* Extend MagicFilter with aiogram-specific operation

* Added tests

* Added changes annotation and update docs
This commit is contained in:
Alex Root Junior 2021-11-24 06:00:37 +02:00 committed by GitHub
parent 092b3f06f2
commit d7be55bc58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 11 deletions

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*
==================