mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
[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:
parent
4599913e18
commit
ac2b0bb198
69 changed files with 1223 additions and 206 deletions
|
|
@ -3,6 +3,7 @@ from .answer_callback_query import AnswerCallbackQuery
|
|||
from .answer_inline_query import AnswerInlineQuery
|
||||
from .answer_pre_checkout_query import AnswerPreCheckoutQuery
|
||||
from .answer_shipping_query import AnswerShippingQuery
|
||||
from .ban_chat_member import BanChatMember
|
||||
from .base import Request, Response, TelegramMethod
|
||||
from .close import Close
|
||||
from .copy_message import CopyMessage
|
||||
|
|
@ -11,6 +12,7 @@ from .create_new_sticker_set import CreateNewStickerSet
|
|||
from .delete_chat_photo import DeleteChatPhoto
|
||||
from .delete_chat_sticker_set import DeleteChatStickerSet
|
||||
from .delete_message import DeleteMessage
|
||||
from .delete_my_commands import DeleteMyCommands
|
||||
from .delete_sticker_from_set import DeleteStickerFromSet
|
||||
from .delete_webhook import DeleteWebhook
|
||||
from .edit_chat_invite_link import EditChatInviteLink
|
||||
|
|
@ -24,6 +26,7 @@ from .forward_message import ForwardMessage
|
|||
from .get_chat import GetChat
|
||||
from .get_chat_administrators import GetChatAdministrators
|
||||
from .get_chat_member import GetChatMember
|
||||
from .get_chat_member_count import GetChatMemberCount
|
||||
from .get_chat_members_count import GetChatMembersCount
|
||||
from .get_file import GetFile
|
||||
from .get_game_high_scores import GetGameHighScores
|
||||
|
|
@ -109,6 +112,7 @@ __all__ = (
|
|||
"SendChatAction",
|
||||
"GetUserProfilePhotos",
|
||||
"GetFile",
|
||||
"BanChatMember",
|
||||
"KickChatMember",
|
||||
"UnbanChatMember",
|
||||
"RestrictChatMember",
|
||||
|
|
@ -129,12 +133,14 @@ __all__ = (
|
|||
"LeaveChat",
|
||||
"GetChat",
|
||||
"GetChatAdministrators",
|
||||
"GetChatMemberCount",
|
||||
"GetChatMembersCount",
|
||||
"GetChatMember",
|
||||
"SetChatStickerSet",
|
||||
"DeleteChatStickerSet",
|
||||
"AnswerCallbackQuery",
|
||||
"SetMyCommands",
|
||||
"DeleteMyCommands",
|
||||
"GetMyCommands",
|
||||
"EditMessageText",
|
||||
"EditMessageCaption",
|
||||
|
|
|
|||
33
aiogram/methods/ban_chat_member.py
Normal file
33
aiogram/methods/ban_chat_member.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class BanChatMember(TelegramMethod[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
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target group or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
user_id: int
|
||||
"""Unique identifier of the target user"""
|
||||
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None
|
||||
"""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."""
|
||||
revoke_messages: Optional[bool] = None
|
||||
"""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."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="banChatMember", data=data)
|
||||
29
aiogram/methods/delete_my_commands.py
Normal file
29
aiogram/methods/delete_my_commands.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional
|
||||
|
||||
from ..types import BotCommandScope
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class DeleteMyCommands(TelegramMethod[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
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
scope: Optional[BotCommandScope] = None
|
||||
"""A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`."""
|
||||
language_code: Optional[str] = None
|
||||
"""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"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="deleteMyCommands", data=data)
|
||||
|
|
@ -2,21 +2,50 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Union
|
||||
|
||||
from ..types import ChatMember
|
||||
from ..types import (
|
||||
ChatMemberAdministrator,
|
||||
ChatMemberBanned,
|
||||
ChatMemberLeft,
|
||||
ChatMemberMember,
|
||||
ChatMemberOwner,
|
||||
ChatMemberRestricted,
|
||||
)
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetChatAdministrators(TelegramMethod[List[ChatMember]]):
|
||||
class GetChatAdministrators(
|
||||
TelegramMethod[
|
||||
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.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getchatadministrators
|
||||
"""
|
||||
|
||||
__returning__ = List[ChatMember]
|
||||
__returning__ = List[
|
||||
Union[
|
||||
ChatMemberOwner,
|
||||
ChatMemberAdministrator,
|
||||
ChatMemberMember,
|
||||
ChatMemberRestricted,
|
||||
ChatMemberLeft,
|
||||
ChatMemberBanned,
|
||||
]
|
||||
]
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
|
|
|
|||
|
|
@ -2,21 +2,46 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Union
|
||||
|
||||
from ..types import ChatMember
|
||||
from ..types import (
|
||||
ChatMemberAdministrator,
|
||||
ChatMemberBanned,
|
||||
ChatMemberLeft,
|
||||
ChatMemberMember,
|
||||
ChatMemberOwner,
|
||||
ChatMemberRestricted,
|
||||
)
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetChatMember(TelegramMethod[ChatMember]):
|
||||
class GetChatMember(
|
||||
TelegramMethod[
|
||||
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.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getchatmember
|
||||
"""
|
||||
|
||||
__returning__ = ChatMember
|
||||
__returning__ = Union[
|
||||
ChatMemberOwner,
|
||||
ChatMemberAdministrator,
|
||||
ChatMemberMember,
|
||||
ChatMemberRestricted,
|
||||
ChatMemberLeft,
|
||||
ChatMemberBanned,
|
||||
]
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
|
|
|
|||
26
aiogram/methods/get_chat_member_count.py
Normal file
26
aiogram/methods/get_chat_member_count.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Union
|
||||
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetChatMemberCount(TelegramMethod[int]):
|
||||
"""
|
||||
Use this method to get the number of members in a chat. Returns *Int* on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getchatmembercount
|
||||
"""
|
||||
|
||||
__returning__ = int
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target supergroup or channel (in the format :code:`@channelusername`)"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="getChatMemberCount", data=data)
|
||||
|
|
@ -10,9 +10,13 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class GetChatMembersCount(TelegramMethod[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#getchatmemberscount
|
||||
Source: https://core.telegram.org/bots/api#getchatmembercount
|
||||
"""
|
||||
|
||||
__returning__ = int
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
|
||||
from ..types import BotCommand
|
||||
from ..types import BotCommand, BotCommandScope
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
|
|
@ -11,13 +11,18 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class GetMyCommands(TelegramMethod[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
|
||||
"""
|
||||
|
||||
__returning__ = List[BotCommand]
|
||||
|
||||
scope: Optional[BotCommandScope] = None
|
||||
"""A JSON-serialized object, describing scope of users. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`."""
|
||||
language_code: Optional[str] = None
|
||||
"""A two-letter ISO 639-1 language code or an empty string"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,13 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class KickChatMember(TelegramMethod[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
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
|
||||
from ..types import BotCommand
|
||||
from ..types import BotCommand, BotCommandScope
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
|
|
@ -11,7 +11,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class SetMyCommands(TelegramMethod[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
|
||||
"""
|
||||
|
|
@ -20,6 +20,10 @@ class SetMyCommands(TelegramMethod[bool]):
|
|||
|
||||
commands: List[BotCommand]
|
||||
"""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."""
|
||||
scope: Optional[BotCommandScope] = None
|
||||
"""A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to :class:`aiogram.types.bot_command_scope_default.BotCommandScopeDefault`."""
|
||||
language_code: Optional[str] = None
|
||||
"""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"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class UnbanChatMember(TelegramMethod[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
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue