[3.x] Bot API 5.3 + Improvements (#618)

* Regenerate API

* Update code

* Fixed command filter for photos

* Fix tests so they are able to run

* Test new and renamed API methods

* Reformat files

* Fix outer_middleware resolution (#637) (#640)

* Fix outer_middleware resolution (#637)

* Reformat files

* Reorder routers when resolve middlewares

Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>

* Added possibility to use empty callback data factory filter

* Rename KeyboardConstructor to KeyboardBuilder

* Fixed type

Co-authored-by: evgfilim1 <evgfilim1@yandex.ru>
This commit is contained in:
Alex Root Junior 2021-07-29 00:40:50 +03:00 committed by GitHub
parent 4599913e18
commit ac2b0bb198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 1223 additions and 206 deletions

View file

@ -28,6 +28,7 @@ from ..methods import (
AnswerInlineQuery,
AnswerPreCheckoutQuery,
AnswerShippingQuery,
BanChatMember,
Close,
CopyMessage,
CreateChatInviteLink,
@ -35,6 +36,7 @@ from ..methods import (
DeleteChatPhoto,
DeleteChatStickerSet,
DeleteMessage,
DeleteMyCommands,
DeleteStickerFromSet,
DeleteWebhook,
EditChatInviteLink,
@ -48,6 +50,7 @@ from ..methods import (
GetChat,
GetChatAdministrators,
GetChatMember,
GetChatMemberCount,
GetChatMembersCount,
GetFile,
GetGameHighScores,
@ -105,9 +108,15 @@ from ..methods import (
from ..types import (
UNSET,
BotCommand,
BotCommandScope,
Chat,
ChatInviteLink,
ChatMember,
ChatMemberAdministrator,
ChatMemberBanned,
ChatMemberLeft,
ChatMemberMember,
ChatMemberOwner,
ChatMemberRestricted,
ChatPermissions,
Downloadable,
File,
@ -1410,6 +1419,35 @@ class Bot(ContextInstanceMixin["Bot"]):
)
return await self(call, request_timeout=request_timeout)
async def ban_chat_member(
self,
chat_id: Union[int, str],
user_id: int,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
revoke_messages: Optional[bool] = None,
request_timeout: Optional[int] = None,
) -> bool:
"""
Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless `unbanned <https://core.telegram.org/bots/api#unbanchatmember>`_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#banchatmember
:param chat_id: Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)
:param user_id: Unique identifier of the target user
:param until_date: Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
:param revoke_messages: Pass :code:`True` to delete all messages from the chat for the user that is being removed. If :code:`False`, the user will be able to see messages in the group that were sent before the user was removed. Always :code:`True` for supergroups and channels.
:param request_timeout: Request timeout
:return: In the case of supergroups and channels, the user will not be able to return to
the chat on their own using invite links, etc. Returns True on success.
"""
call = BanChatMember(
chat_id=chat_id,
user_id=user_id,
until_date=until_date,
revoke_messages=revoke_messages,
)
return await self(call, request_timeout=request_timeout)
async def kick_chat_member(
self,
chat_id: Union[int, str],
@ -1419,9 +1457,13 @@ class Bot(ContextInstanceMixin["Bot"]):
request_timeout: Optional[int] = None,
) -> bool:
"""
Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless `unbanned <https://core.telegram.org/bots/api#unbanchatmember>`_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success.
.. warning:
Source: https://core.telegram.org/bots/api#kickchatmember
Renamed from :code:`kickChatMember` in 5.3 bot API version and can be removed in near future
Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless `unbanned <https://core.telegram.org/bots/api#unbanchatmember>`_ first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#banchatmember
:param chat_id: Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)
:param user_id: Unique identifier of the target user
@ -1447,7 +1489,7 @@ class Bot(ContextInstanceMixin["Bot"]):
request_timeout: Optional[int] = None,
) -> bool:
"""
Use this method to unban a previously kicked user in a supergroup or channel. The user will **not** return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be **removed** from the chat. If you don't want this, use the parameter *only_if_banned*. Returns :code:`True` on success.
Use this method to unban a previously banned user in a supergroup or channel. The user will **not** return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be **removed** from the chat. If you don't want this, use the parameter *only_if_banned*. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#unbanchatmember
@ -1884,7 +1926,16 @@ class Bot(ContextInstanceMixin["Bot"]):
self,
chat_id: Union[int, str],
request_timeout: Optional[int] = None,
) -> List[ChatMember]:
) -> List[
Union[
ChatMemberOwner,
ChatMemberAdministrator,
ChatMemberMember,
ChatMemberRestricted,
ChatMemberLeft,
ChatMemberBanned,
]
]:
"""
Use this method to get a list of administrators in a chat. On success, returns an Array of :class:`aiogram.types.chat_member.ChatMember` objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
@ -1902,7 +1953,7 @@ class Bot(ContextInstanceMixin["Bot"]):
)
return await self(call, request_timeout=request_timeout)
async def get_chat_members_count(
async def get_chat_member_count(
self,
chat_id: Union[int, str],
request_timeout: Optional[int] = None,
@ -1910,7 +1961,30 @@ class Bot(ContextInstanceMixin["Bot"]):
"""
Use this method to get the number of members in a chat. Returns *Int* on success.
Source: https://core.telegram.org/bots/api#getchatmemberscount
Source: https://core.telegram.org/bots/api#getchatmembercount
:param chat_id: Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)
:param request_timeout: Request timeout
:return: Returns Int on success.
"""
call = GetChatMemberCount(
chat_id=chat_id,
)
return await self(call, request_timeout=request_timeout)
async def get_chat_members_count(
self,
chat_id: Union[int, str],
request_timeout: Optional[int] = None,
) -> int:
"""
.. warning:
Renamed from :code:`getChatMembersCount` in 5.3 bot API version and can be removed in near future
Use this method to get the number of members in a chat. Returns *Int* on success.
Source: https://core.telegram.org/bots/api#getchatmembercount
:param chat_id: Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)
:param request_timeout: Request timeout
@ -1926,7 +2000,14 @@ class Bot(ContextInstanceMixin["Bot"]):
chat_id: Union[int, str],
user_id: int,
request_timeout: Optional[int] = None,
) -> ChatMember:
) -> Union[
ChatMemberOwner,
ChatMemberAdministrator,
ChatMemberMember,
ChatMemberRestricted,
ChatMemberLeft,
ChatMemberBanned,
]:
"""
Use this method to get information about a member of a chat. Returns a :class:`aiogram.types.chat_member.ChatMember` object on success.
@ -2022,35 +2103,71 @@ class Bot(ContextInstanceMixin["Bot"]):
async def set_my_commands(
self,
commands: List[BotCommand],
scope: Optional[BotCommandScope] = None,
language_code: Optional[str] = None,
request_timeout: Optional[int] = None,
) -> bool:
"""
Use this method to change the list of the bot's commands. Returns :code:`True` on success.
Use this method to change the list of the bot's commands. See `https://core.telegram.org/bots#commands <https://core.telegram.org/bots#commands>`_`https://core.telegram.org/bots#commands <https://core.telegram.org/bots#commands>`_ for more details about bot commands. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#setmycommands
:param commands: A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
:param scope: A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.
:param language_code: A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
:param request_timeout: Request timeout
:return: Returns True on success.
"""
call = SetMyCommands(
commands=commands,
scope=scope,
language_code=language_code,
)
return await self(call, request_timeout=request_timeout)
async def delete_my_commands(
self,
scope: Optional[BotCommandScope] = None,
language_code: Optional[str] = None,
request_timeout: Optional[int] = None,
) -> bool:
"""
Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, `higher level commands <https://core.telegram.org/bots/api#determining-list-of-commands>`_ will be shown to affected users. Returns :code:`True` on success.
Source: https://core.telegram.org/bots/api#deletemycommands
:param scope: A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.
:param language_code: A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
:param request_timeout: Request timeout
:return: Returns True on success.
"""
call = DeleteMyCommands(
scope=scope,
language_code=language_code,
)
return await self(call, request_timeout=request_timeout)
async def get_my_commands(
self,
scope: Optional[BotCommandScope] = None,
language_code: Optional[str] = None,
request_timeout: Optional[int] = None,
) -> List[BotCommand]:
"""
Use this method to get the current list of the bot's commands. Requires no parameters. Returns Array of :class:`aiogram.types.bot_command.BotCommand` on success.
Use this method to get the current list of the bot's commands for the given scope and user language. Returns Array of :class:`aiogram.types.bot_command.BotCommand` on success. If commands aren't set, an empty list is returned.
Source: https://core.telegram.org/bots/api#getmycommands
:param scope: A JSON-serialized object, describing scope of users. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`.
:param language_code: A two-letter ISO 639-1 language code or an empty string
:param request_timeout: Request timeout
:return: Returns Array of BotCommand on success.
:return: Returns Array of BotCommand on success. If commands aren't set, an empty list is
returned.
"""
call = GetMyCommands()
call = GetMyCommands(
scope=scope,
language_code=language_code,
)
return await self(call, request_timeout=request_timeout)
# =============================================================================================