mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
[3.0] Bot API 5.1 + FSM + Utils (#525)
* Regenerate corresponding to Bot API 5.1 * Added base of FSM. Markup constructor and small refactoring * Fix dependencies * Fix mypy windows error * Move StatesGroup.get_root() from meta to class * Fixed chat and user constraints * Update pipeline * Remove docs pipeline * Added GLOBAL_USER FSM strategy * Reformat code * Fixed Dispatcher._process_update * Bump Bot API 5.2. Added integration with MagicFilter * Coverage
This commit is contained in:
parent
a6f824a117
commit
0e72d8e65b
265 changed files with 2921 additions and 1324 deletions
|
|
@ -6,12 +6,14 @@ from .answer_shipping_query import AnswerShippingQuery
|
|||
from .base import Request, Response, TelegramMethod
|
||||
from .close import Close
|
||||
from .copy_message import CopyMessage
|
||||
from .create_chat_invite_link import CreateChatInviteLink
|
||||
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_sticker_from_set import DeleteStickerFromSet
|
||||
from .delete_webhook import DeleteWebhook
|
||||
from .edit_chat_invite_link import EditChatInviteLink
|
||||
from .edit_message_caption import EditMessageCaption
|
||||
from .edit_message_live_location import EditMessageLiveLocation
|
||||
from .edit_message_media import EditMessageMedia
|
||||
|
|
@ -37,6 +39,7 @@ from .log_out import LogOut
|
|||
from .pin_chat_message import PinChatMessage
|
||||
from .promote_chat_member import PromoteChatMember
|
||||
from .restrict_chat_member import RestrictChatMember
|
||||
from .revoke_chat_invite_link import RevokeChatInviteLink
|
||||
from .send_animation import SendAnimation
|
||||
from .send_audio import SendAudio
|
||||
from .send_chat_action import SendChatAction
|
||||
|
|
@ -113,6 +116,9 @@ __all__ = (
|
|||
"SetChatAdministratorCustomTitle",
|
||||
"SetChatPermissions",
|
||||
"ExportChatInviteLink",
|
||||
"CreateChatInviteLink",
|
||||
"EditChatInviteLink",
|
||||
"RevokeChatInviteLink",
|
||||
"SetChatPhoto",
|
||||
"DeleteChatPhoto",
|
||||
"SetChatTitle",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class CopyMessage(TelegramMethod[MessageId]):
|
||||
"""
|
||||
Use this method to copy messages of any kind. The method is analogous to the method :class:`aiogram.methods.forward_messages.ForwardMessages`, but the copied message doesn't have a link to the original message. Returns the :class:`aiogram.types.message_id.MessageId` of the sent message on success.
|
||||
Use this method to copy messages of any kind. Service messages and invoice messages can't be copied. The method is analogous to the method :class:`aiogram.methods.forward_message.ForwardMessage`, but the copied message doesn't have a link to the original message. Returns the :class:`aiogram.types.message_id.MessageId` of the sent message on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#copymessage
|
||||
"""
|
||||
|
|
|
|||
31
aiogram/methods/create_chat_invite_link.py
Normal file
31
aiogram/methods/create_chat_invite_link.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from ..types import ChatInviteLink
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class CreateChatInviteLink(TelegramMethod[ChatInviteLink]):
|
||||
"""
|
||||
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The link can be revoked using the method :class:`aiogram.methods.revoke_chat_invite_link.RevokeChatInviteLink`. Returns the new invite link as :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#createchatinvitelink
|
||||
"""
|
||||
|
||||
__returning__ = ChatInviteLink
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
expire_date: Optional[int] = None
|
||||
"""Point in time (Unix timestamp) when the link will expire"""
|
||||
member_limit: Optional[int] = None
|
||||
"""Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="createChatInviteLink", data=data)
|
||||
33
aiogram/methods/edit_chat_invite_link.py
Normal file
33
aiogram/methods/edit_chat_invite_link.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from ..types import ChatInviteLink
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class EditChatInviteLink(TelegramMethod[ChatInviteLink]):
|
||||
"""
|
||||
Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the edited invite link as a :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#editchatinvitelink
|
||||
"""
|
||||
|
||||
__returning__ = ChatInviteLink
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
invite_link: str
|
||||
"""The invite link to edit"""
|
||||
expire_date: Optional[int] = None
|
||||
"""Point in time (Unix timestamp) when the link will expire"""
|
||||
member_limit: Optional[int] = None
|
||||
"""Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="editChatInviteLink", data=data)
|
||||
|
|
@ -10,9 +10,9 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class ExportChatInviteLink(TelegramMethod[str]):
|
||||
"""
|
||||
Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as *String* on success.
|
||||
Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as *String* on success.
|
||||
|
||||
Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` — after this the link will become available to the bot via the :class:`aiogram.methods.get_chat.GetChat` method. If your bot needs to generate a new invite link replacing its previous one, use :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` again.
|
||||
Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` or by calling the :class:`aiogram.methods.get_chat.GetChat` method. If your bot needs to generate a new primary invite link replacing its previous one, use :class:`aiogram.methods.export_chat_invite_link.ExportChatInviteLink` again.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#exportchatinvitelink
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
|
||||
class ForwardMessage(TelegramMethod[Message]):
|
||||
"""
|
||||
Use this method to forward messages of any kind. On success, the sent :class:`aiogram.types.message.Message` is returned.
|
||||
Use this method to forward messages of any kind. Service messages can't be forwarded. On success, the sent :class:`aiogram.types.message.Message` is returned.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#forwardmessage
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class GetUpdates(TelegramMethod[List[Update]]):
|
|||
timeout: Optional[int] = None
|
||||
"""Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only."""
|
||||
allowed_updates: Optional[List[str]] = None
|
||||
"""A JSON-serialized list of the update types you want your bot to receive. For example, specify ['message', 'edited_channel_post', 'callback_query'] to only receive updates of these types. See :class:`aiogram.types.update.Update` for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used."""
|
||||
"""A JSON-serialized list of the update types you want your bot to receive. For example, specify ['message', 'edited_channel_post', 'callback_query'] to only receive updates of these types. See :class:`aiogram.types.update.Update` for a complete list of available update types. Specify an empty list to receive all update types except *chat_member* (default). If not specified, the previous setting will be used."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ class KickChatMember(TelegramMethod[bool]):
|
|||
"""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()
|
||||
|
|
|
|||
|
|
@ -23,22 +23,26 @@ class PromoteChatMember(TelegramMethod[bool]):
|
|||
"""Unique identifier of the target user"""
|
||||
is_anonymous: Optional[bool] = None
|
||||
"""Pass :code:`True`, if the administrator's presence in the chat is hidden"""
|
||||
can_change_info: Optional[bool] = None
|
||||
"""Pass True, if the administrator can change chat title, photo and other settings"""
|
||||
can_manage_chat: Optional[bool] = None
|
||||
"""Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege"""
|
||||
can_post_messages: Optional[bool] = None
|
||||
"""Pass True, if the administrator can create channel posts, channels only"""
|
||||
can_edit_messages: Optional[bool] = None
|
||||
"""Pass True, if the administrator can edit messages of other users and can pin messages, channels only"""
|
||||
can_delete_messages: Optional[bool] = None
|
||||
"""Pass True, if the administrator can delete messages of other users"""
|
||||
can_invite_users: Optional[bool] = None
|
||||
"""Pass True, if the administrator can invite new users to the chat"""
|
||||
can_manage_voice_chats: Optional[bool] = None
|
||||
"""Pass True, if the administrator can manage voice chats"""
|
||||
can_restrict_members: Optional[bool] = None
|
||||
"""Pass True, if the administrator can restrict, ban or unban chat members"""
|
||||
can_pin_messages: Optional[bool] = None
|
||||
"""Pass True, if the administrator can pin messages, supergroups only"""
|
||||
can_promote_members: Optional[bool] = None
|
||||
"""Pass True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)"""
|
||||
can_change_info: Optional[bool] = None
|
||||
"""Pass True, if the administrator can change chat title, photo and other settings"""
|
||||
can_invite_users: Optional[bool] = None
|
||||
"""Pass True, if the administrator can invite new users to the chat"""
|
||||
can_pin_messages: Optional[bool] = None
|
||||
"""Pass True, if the administrator can pin messages, supergroups only"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
|
|
|||
29
aiogram/methods/revoke_chat_invite_link.py
Normal file
29
aiogram/methods/revoke_chat_invite_link.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Union
|
||||
|
||||
from ..types import ChatInviteLink
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class RevokeChatInviteLink(TelegramMethod[ChatInviteLink]):
|
||||
"""
|
||||
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the revoked invite link as :class:`aiogram.types.chat_invite_link.ChatInviteLink` object.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#revokechatinvitelink
|
||||
"""
|
||||
|
||||
__returning__ = ChatInviteLink
|
||||
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier of the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
invite_link: str
|
||||
"""The invite link to revoke"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="revokeChatInviteLink", data=data)
|
||||
|
|
@ -27,7 +27,7 @@ class SendDice(TelegramMethod[Message]):
|
|||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
emoji: Optional[str] = None
|
||||
"""Emoji on which the dice throw animation is based. Currently, must be one of '🎲', '🎯', '🏀', '⚽', or '🎰'. Dice can have values 1-6 for '🎲' and '🎯', values 1-5 for '🏀' and '⚽', and values 1-64 for '🎰'. Defaults to '🎲'"""
|
||||
"""Emoji on which the dice throw animation is based. Currently, must be one of '🎲', '🎯', '🏀', '⚽', '🎳', or '🎰'. Dice can have values 1-6 for '🎲', '🎯' and '🎳', values 1-5 for '🏀' and '⚽', and values 1-64 for '🎰'. Defaults to '🎲'"""
|
||||
disable_notification: Optional[bool] = None
|
||||
"""Sends the message `silently <https://telegram.org/blog/channels-2-0#silent-messages>`_. Users will receive a notification with no sound."""
|
||||
reply_to_message_id: Optional[int] = None
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
||||
|
||||
from ..types import InlineKeyboardMarkup, LabeledPrice, Message
|
||||
from .base import Request, TelegramMethod
|
||||
|
|
@ -18,8 +18,8 @@ class SendInvoice(TelegramMethod[Message]):
|
|||
|
||||
__returning__ = Message
|
||||
|
||||
chat_id: int
|
||||
"""Unique identifier for the target private chat"""
|
||||
chat_id: Union[int, str]
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
title: str
|
||||
"""Product name, 1-32 characters"""
|
||||
description: str
|
||||
|
|
@ -28,12 +28,16 @@ class SendInvoice(TelegramMethod[Message]):
|
|||
"""Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes."""
|
||||
provider_token: str
|
||||
"""Payments provider token, obtained via `Botfather <https://t.me/botfather>`_"""
|
||||
start_parameter: str
|
||||
"""Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter"""
|
||||
currency: str
|
||||
"""Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_"""
|
||||
prices: List[LabeledPrice]
|
||||
"""Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)"""
|
||||
max_tip_amount: Optional[int] = None
|
||||
"""The maximum accepted amount for tips in the *smallest units* of the currency (integer, **not** float/double). For example, for a maximum tip of :code:`US$ 1.45` pass :code:`max_tip_amount = 145`. See the *exp* parameter in `currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0"""
|
||||
suggested_tip_amounts: Optional[List[int]] = None
|
||||
"""A JSON-serialized array of suggested amounts of tips in the *smallest units* of the currency (integer, **not** float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed *max_tip_amount*."""
|
||||
start_parameter: Optional[str] = None
|
||||
"""Unique deep-linking parameter. If left empty, **forwarded copies** of the sent message will have a *Pay* button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a *URL* button with a deep link to the bot (instead of a *Pay* button), with the value used as the start parameter"""
|
||||
provider_data: Optional[str] = None
|
||||
"""A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider."""
|
||||
photo_url: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class SetWebhook(TelegramMethod[bool]):
|
|||
max_connections: Optional[int] = None
|
||||
"""Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to *40*. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput."""
|
||||
allowed_updates: Optional[List[str]] = None
|
||||
"""A JSON-serialized list of the update types you want your bot to receive. For example, specify ['message', 'edited_channel_post', 'callback_query'] to only receive updates of these types. See :class:`aiogram.types.update.Update` for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used."""
|
||||
"""A JSON-serialized list of the update types you want your bot to receive. For example, specify ['message', 'edited_channel_post', 'callback_query'] to only receive updates of these types. See :class:`aiogram.types.update.Update` for a complete list of available update types. Specify an empty list to receive all update types except *chat_member* (default). If not specified, the previous setting will be used."""
|
||||
drop_pending_updates: Optional[bool] = None
|
||||
"""Pass :code:`True` to drop all pending updates"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue