mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
[3.x] Bot API 6.0 (#890)
* Base implementation * Bump license * Revert re-generated tests * Fix tests, improved docs * Remove TODO * Removed unreachable code * Changed type of `last_synchronization_error_date` * Fixed wrongly cleaned code
This commit is contained in:
parent
286cf39c8a
commit
497436595d
81 changed files with 1942 additions and 147 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 .answer_web_app_query import AnswerWebAppQuery
|
||||
from .approve_chat_join_request import ApproveChatJoinRequest
|
||||
from .ban_chat_member import BanChatMember
|
||||
from .ban_chat_sender_chat import BanChatSenderChat
|
||||
|
|
@ -31,10 +32,12 @@ 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_chat_menu_button import GetChatMenuButton
|
||||
from .get_file import GetFile
|
||||
from .get_game_high_scores import GetGameHighScores
|
||||
from .get_me import GetMe
|
||||
from .get_my_commands import GetMyCommands
|
||||
from .get_my_default_administrator_rights import GetMyDefaultAdministratorRights
|
||||
from .get_sticker_set import GetStickerSet
|
||||
from .get_updates import GetUpdates
|
||||
from .get_user_profile_photos import GetUserProfilePhotos
|
||||
|
|
@ -66,12 +69,14 @@ from .send_video_note import SendVideoNote
|
|||
from .send_voice import SendVoice
|
||||
from .set_chat_administrator_custom_title import SetChatAdministratorCustomTitle
|
||||
from .set_chat_description import SetChatDescription
|
||||
from .set_chat_menu_button import SetChatMenuButton
|
||||
from .set_chat_permissions import SetChatPermissions
|
||||
from .set_chat_photo import SetChatPhoto
|
||||
from .set_chat_sticker_set import SetChatStickerSet
|
||||
from .set_chat_title import SetChatTitle
|
||||
from .set_game_score import SetGameScore
|
||||
from .set_my_commands import SetMyCommands
|
||||
from .set_my_default_administrator_rights import SetMyDefaultAdministratorRights
|
||||
from .set_passport_data_errors import SetPassportDataErrors
|
||||
from .set_sticker_position_in_set import SetStickerPositionInSet
|
||||
from .set_sticker_set_thumb import SetStickerSetThumb
|
||||
|
|
@ -150,6 +155,10 @@ __all__ = (
|
|||
"SetMyCommands",
|
||||
"DeleteMyCommands",
|
||||
"GetMyCommands",
|
||||
"SetChatMenuButton",
|
||||
"GetChatMenuButton",
|
||||
"SetMyDefaultAdministratorRights",
|
||||
"GetMyDefaultAdministratorRights",
|
||||
"EditMessageText",
|
||||
"EditMessageCaption",
|
||||
"EditMessageMedia",
|
||||
|
|
@ -165,6 +174,7 @@ __all__ = (
|
|||
"DeleteStickerFromSet",
|
||||
"SetStickerSetThumb",
|
||||
"AnswerInlineQuery",
|
||||
"AnswerWebAppQuery",
|
||||
"SendInvoice",
|
||||
"AnswerShippingQuery",
|
||||
"AnswerPreCheckoutQuery",
|
||||
|
|
|
|||
31
aiogram/methods/answer_web_app_query.py
Normal file
31
aiogram/methods/answer_web_app_query.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict
|
||||
|
||||
from ..types import InlineQueryResult, SentWebAppMessage
|
||||
from .base import Request, TelegramMethod, prepare_parse_mode
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class AnswerWebAppQuery(TelegramMethod[SentWebAppMessage]):
|
||||
"""
|
||||
Use this method to set the result of an interaction with a `Web App <https://core.telegram.org/bots/webapps>`_ and send a corresponding message on behalf of the user to the chat from which the query originated. On success, a :class:`aiogram.types.sent_web_app_message.SentWebAppMessage` object is returned.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#answerwebappquery
|
||||
"""
|
||||
|
||||
__returning__ = SentWebAppMessage
|
||||
|
||||
web_app_query_id: str
|
||||
"""Unique identifier for the query to be answered"""
|
||||
result: InlineQueryResult
|
||||
"""A JSON-serialized object describing the message to be sent"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
prepare_parse_mode(
|
||||
bot, data["result"], parse_mode_property="parse_mode", entities_property="entities"
|
||||
)
|
||||
return Request(method="answerWebAppQuery", data=data)
|
||||
|
|
@ -21,7 +21,7 @@ class CreateNewStickerSet(TelegramMethod[bool]):
|
|||
user_id: int
|
||||
"""User identifier of created sticker set owner"""
|
||||
name: str
|
||||
"""Short name of sticker set, to be used in :code:`t.me/addstickers/` URLs (e.g., *animals*). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in *'_by_<bot username>'*. *<bot_username>* is case insensitive. 1-64 characters."""
|
||||
"""Short name of sticker set, to be used in :code:`t.me/addstickers/` URLs (e.g., *animals*). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in :code:`"_by_<bot_username>"`. :code:`<bot_username>` is case insensitive. 1-64 characters."""
|
||||
title: str
|
||||
"""Sticker set title, 1-64 characters"""
|
||||
emojis: str
|
||||
|
|
|
|||
27
aiogram/methods/get_chat_menu_button.py
Normal file
27
aiogram/methods/get_chat_menu_button.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from ..types import MenuButton, MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetChatMenuButton(TelegramMethod[MenuButton]):
|
||||
"""
|
||||
Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns :class:`aiogram.types.menu_button.MenuButton` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getchatmenubutton
|
||||
"""
|
||||
|
||||
__returning__ = Union[MenuButtonDefault, MenuButtonWebApp, MenuButtonCommands]
|
||||
|
||||
chat_id: Optional[int] = None
|
||||
"""Unique identifier for the target private chat. If not specified, default bot's menu button will be returned"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="getChatMenuButton", data=data)
|
||||
27
aiogram/methods/get_my_default_administrator_rights.py
Normal file
27
aiogram/methods/get_my_default_administrator_rights.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional
|
||||
|
||||
from ..types import ChatAdministratorRights
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class GetMyDefaultAdministratorRights(TelegramMethod[ChatAdministratorRights]):
|
||||
"""
|
||||
Use this method to get the current default administrator rights of the bot. Returns :class:`aiogram.types.chat_administrator_rights.ChatAdministratorRights` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmydefaultadministratorrights
|
||||
"""
|
||||
|
||||
__returning__ = ChatAdministratorRights
|
||||
|
||||
for_channels: Optional[bool] = None
|
||||
"""Pass :code:`True` to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="getMyDefaultAdministratorRights", data=data)
|
||||
|
|
@ -31,8 +31,8 @@ class PromoteChatMember(TelegramMethod[bool]):
|
|||
"""Pass :code:`True`, if the administrator can edit messages of other users and can pin messages, channels only"""
|
||||
can_delete_messages: Optional[bool] = None
|
||||
"""Pass :code:`True`, if the administrator can delete messages of other users"""
|
||||
can_manage_voice_chats: Optional[bool] = None
|
||||
"""Pass :code:`True`, if the administrator can manage voice chats"""
|
||||
can_manage_video_chats: Optional[bool] = None
|
||||
"""Pass :code:`True`, if the administrator can manage video chats"""
|
||||
can_restrict_members: Optional[bool] = None
|
||||
"""Pass :code:`True`, if the administrator can restrict, ban or unban chat members"""
|
||||
can_promote_members: Optional[bool] = None
|
||||
|
|
|
|||
29
aiogram/methods/set_chat_menu_button.py
Normal file
29
aiogram/methods/set_chat_menu_button.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional
|
||||
|
||||
from ..types import MenuButton
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class SetChatMenuButton(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to change the bot's menu button in a private chat, or the default menu button. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setchatmenubutton
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
chat_id: Optional[int] = None
|
||||
"""Unique identifier for the target private chat. If not specified, default bot's menu button will be changed"""
|
||||
menu_button: Optional[MenuButton] = None
|
||||
"""A JSON-serialized object for the new bot's menu button. Defaults to :class:`aiogram.types.menu_button_default.MenuButtonDefault`"""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="setChatMenuButton", data=data)
|
||||
29
aiogram/methods/set_my_default_administrator_rights.py
Normal file
29
aiogram/methods/set_my_default_administrator_rights.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional
|
||||
|
||||
from ..types import ChatAdministratorRights
|
||||
from .base import Request, TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..client.bot import Bot
|
||||
|
||||
|
||||
class SetMyDefaultAdministratorRights(TelegramMethod[bool]):
|
||||
"""
|
||||
Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns :code:`True` on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmydefaultadministratorrights
|
||||
"""
|
||||
|
||||
__returning__ = bool
|
||||
|
||||
rights: Optional[ChatAdministratorRights] = None
|
||||
"""A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared."""
|
||||
for_channels: Optional[bool] = None
|
||||
"""Pass :code:`True` to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed."""
|
||||
|
||||
def build_request(self, bot: Bot) -> Request:
|
||||
data: Dict[str, Any] = self.dict()
|
||||
|
||||
return Request(method="setMyDefaultAdministratorRights", data=data)
|
||||
Loading…
Add table
Add a link
Reference in a new issue