Bot API 5.7 and some new features (#834)

* Update API, added some new features

* Fixed unknown chat_action value

* Separate events from dispatcher messages

* Disabled cache for I18n LazyProxy

* Rework events isolation

* Added chat member status changed filter, update Bot API 5.7, other small changes

* Improve exceptions in chat member status filter

* Fixed tests, covered flags and events isolation modules

* Try to fix flake8 unused type ignore

* Fixed linter error

* Cover chat member updated filter

* Cover chat action sender

* Added docs for chat action util

* Try to fix tests for python <= 3.9

* Fixed headers

* Added docs for flags functionality

* Added docs for chat_member_updated filter

* Added change notes

* Update dependencies and fix mypy checks

* Bump version
This commit is contained in:
Alex Root Junior 2022-02-19 01:45:59 +02:00 committed by GitHub
parent ac7f2dc408
commit 7776cf9cf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 2485 additions and 502 deletions

View file

@ -0,0 +1,103 @@
=================
ChatMemberUpdated
=================
.. autoclass:: aiogram.dispatcher.filters.chat_member_updated.ChatMemberUpdatedFilter
:members:
:member-order: bysource
:undoc-members: False
You can import from :code:`aiogram.dispatcher.filters` all available
variants of `statuses`_, `status groups`_ or `transitions`_:
Statuses
========
+-------------------------+--------------------------------------+
| name | Description |
+=========================+======================================+
| :code:`CREATOR` | Chat owner |
+-------------------------+--------------------------------------+
| :code:`ADMINISTRATOR` | Chat administrator |
+-------------------------+--------------------------------------+
| :code:`MEMBER` | Member of the chat |
+-------------------------+--------------------------------------+
| :code:`RESTRICTED` | Restricted user (can be not member) |
+-------------------------+--------------------------------------+
| :code:`LEFT` | Isn't member of the chat |
+-------------------------+--------------------------------------+
| :code:`KICKED` | Kicked member by administrators |
+-------------------------+--------------------------------------+
Statuses can be extended with `is_member` flag by prefixing with
:code:`+` (for :code:`is_member == True)` or :code:`-` (for :code:`is_member == False`) symbol,
like :code:`+RESTRICTED` or :code:`-RESTRICTED`
Status groups
=============
The particular statuses can be combined via bitwise :code:`or` operator, like :code:`CREATOR | ADMINISTRATOR`
+-------------------------+-----------------------------------------------------------------------------------+
| name | Description |
+=========================+===================================================================================+
| :code:`IS_MEMBER` | Combination of :code:`(CREATOR | ADMINISTRATOR | MEMBER | +RESTRICTED)` statuses. |
+-------------------------+-----------------------------------------------------------------------------------+
| :code:`IS_ADMIN` | Combination of :code:`(CREATOR | ADMINISTRATOR)` statuses. |
+-------------------------+-----------------------------------------------------------------------------------+
| :code:`IS_NOT_MEMBER` | Combination of :code:`(LEFT | KICKED | -RESTRICTED)` statuses. |
+-------------------------+-----------------------------------------------------------------------------------+
Transitions
===========
Transitions can be defined via bitwise shift operators :code:`>>` and :code:`<<`.
Old chat member status should be defined in the left side for :code:`>>` operator (right side for :code:`<<`)
and new status should be specified on the right side for :code:`>>` operator (left side for :code:`<<`)
The direction of transition can be changed via bitwise inversion operator: :code:`~JOIN_TRANSITION`
will produce swap of old and new statuses.
+-----------------------------+-----------------------------------------------------------------------+
| name | Description |
+=============================+=======================================================================+
| :code:`JOIN_TRANSITION` | Means status changed from :code:`IS_NOT_MEMBER` to :code:`IS_MEMBER` |
| | (:code:`IS_NOT_MEMBER >> IS_MEMBER`) |
+-----------------------------+-----------------------------------------------------------------------+
| :code:`LEAVE_TRANSITION` | Means status changed from :code:`IS_MEMBER` to :code:`IS_NOT_MEMBER` |
| | (:code:`~JOIN_TRANSITION`) |
+-----------------------------+-----------------------------------------------------------------------+
| :code:`PROMOTED_TRANSITION` | Means status changed from |
| | :code:`(MEMBER | RESTRICTED | LEFT | KICKED) >> ADMINISTRATOR` |
| | (:code:`(MEMBER | RESTRICTED | LEFT | KICKED) >> ADMINISTRATOR`) |
+-----------------------------+-----------------------------------------------------------------------+
.. note::
Note that if you define the status unions (via :code:`|`) you will need to add brackets for the statement
before use shift operator in due to operator priorities.
Usage
=====
Handle user leave or join events
.. code-block:: python
from aiogram.dispatcher.filters import IS_MEMBER, IS_NOT_MEMBER
@router.chat_member(chat_member_updated=IS_MEMBER >> IS_NOT_MEMBER)
async def on_user_leave(event: ChatMemberUpdated): ...
@router.chat_member(chat_member_updated=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.
Allowed handlers
================
Allowed update types for this filter:
- `my_chat_member`
- `chat_member`

View file

@ -18,6 +18,7 @@ Here is list of builtin filters:
command
content_types
text
chat_member_updated
exception
magic_filters
magic_data
@ -83,7 +84,7 @@ Bound Filters with only default arguments will be automatically applied with def
to each handler in the router and nested routers to which this filter is bound.
For example, although we do not specify :code:`chat_type` in the handler filters,
but since the filter has a default value, the filter will be applied to the handler
but since the filter has a default value, the filter will be applied to the handler
with a default value :code:`private`:
.. code-block:: python