Added full support of Bot API 6.5 (#1112)

* Added full support of Bot API 6.5

* Shut up, linters (Fixed errors)

* Oops. Added lost files.

* Fixed tests

* Added changes description

* Update description from docs

* Fixed anchors

* Update Butcher

* Added danger zone to changelog

* Type
This commit is contained in:
Alex Root Junior 2023-02-04 19:53:32 +02:00 committed by GitHub
parent 3428924d63
commit e59d4652bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 1218 additions and 184 deletions

View file

@ -31,6 +31,7 @@ from .chat_member_restricted import ChatMemberRestricted
from .chat_member_updated import ChatMemberUpdated
from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto
from .chat_shared import ChatShared
from .chosen_inline_result import ChosenInlineResult
from .contact import Contact
from .dice import Dice
@ -90,6 +91,8 @@ from .input_venue_message_content import InputVenueMessageContent
from .invoice import Invoice
from .keyboard_button import KeyboardButton
from .keyboard_button_poll_type import KeyboardButtonPollType
from .keyboard_button_request_chat import KeyboardButtonRequestChat
from .keyboard_button_request_user import KeyboardButtonRequestUser
from .labeled_price import LabeledPrice
from .location import Location
from .login_url import LoginUrl
@ -136,6 +139,7 @@ from .successful_payment import SuccessfulPayment
from .update import Update
from .user import User
from .user_profile_photos import UserProfilePhotos
from .user_shared import UserShared
from .venue import Venue
from .video import Video
from .video_chat_ended import VideoChatEnded
@ -179,6 +183,7 @@ __all__ = (
"ChatMemberUpdated",
"ChatPermissions",
"ChatPhoto",
"ChatShared",
"ChosenInlineResult",
"Contact",
"ContentType",
@ -240,6 +245,8 @@ __all__ = (
"Invoice",
"KeyboardButton",
"KeyboardButtonPollType",
"KeyboardButtonRequestChat",
"KeyboardButtonRequestUser",
"LabeledPrice",
"Location",
"LoginUrl",
@ -287,6 +294,7 @@ __all__ = (
"Update",
"User",
"UserProfilePhotos",
"UserShared",
"Venue",
"Video",
"VideoChatEnded",

View file

@ -506,7 +506,7 @@ class Chat(TelegramObject):
- :code:`chat_id`
Use this method to get information about a member of a chat. The method is guaranteed to work for other users, only if the bot is an administrator in the chat. Returns a :class:`aiogram.types.chat_member.ChatMember` object on success.
Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat. Returns a :class:`aiogram.types.chat_member.ChatMember` object on success.
Source: https://core.telegram.org/bots/api#getchatmember
@ -698,6 +698,7 @@ class Chat(TelegramObject):
def set_permissions(
self,
permissions: ChatPermissions,
use_independent_chat_permissions: Optional[bool] = None,
**kwargs: Any,
) -> SetChatPermissions:
"""
@ -711,6 +712,7 @@ class Chat(TelegramObject):
Source: https://core.telegram.org/bots/api#setchatpermissions
:param permissions: A JSON-serialized object for new default chat permissions
:param use_independent_chat_permissions: Pass :code:`True` if chat permissions are set independently. Otherwise, the *can_send_other_messages* and *can_add_web_page_previews* permissions will imply the *can_send_messages*, *can_send_audios*, *can_send_documents*, *can_send_photos*, *can_send_videos*, *can_send_video_notes*, and *can_send_voice_notes* permissions; the *can_send_polls* permission will imply the *can_send_messages* permission.
:return: instance of method :class:`aiogram.methods.set_chat_permissions.SetChatPermissions`
"""
# DO NOT EDIT MANUALLY!!!
@ -721,6 +723,7 @@ class Chat(TelegramObject):
return SetChatPermissions(
chat_id=self.id,
permissions=permissions,
use_independent_chat_permissions=use_independent_chat_permissions,
**kwargs,
)
@ -759,7 +762,7 @@ class Chat(TelegramObject):
:param can_delete_messages: Pass :code:`True` if the administrator can delete messages of other users
:param can_manage_video_chats: Pass :code:`True` if the administrator can manage video chats
:param can_restrict_members: Pass :code:`True` if the administrator can restrict, ban or unban chat members
:param can_promote_members: Pass :code:`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)
:param can_promote_members: Pass :code:`True` if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by him)
:param can_change_info: Pass :code:`True` if the administrator can change chat title, photo and other settings
:param can_invite_users: Pass :code:`True` if the administrator can invite new users to the chat
:param can_pin_messages: Pass :code:`True` if the administrator can pin messages, supergroups only
@ -793,6 +796,7 @@ class Chat(TelegramObject):
self,
user_id: int,
permissions: ChatPermissions,
use_independent_chat_permissions: Optional[bool] = None,
until_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = None,
**kwargs: Any,
) -> RestrictChatMember:
@ -808,6 +812,7 @@ class Chat(TelegramObject):
:param user_id: Unique identifier of the target user
:param permissions: A JSON-serialized object for new user permissions
:param use_independent_chat_permissions: Pass :code:`True` if chat permissions are set independently. Otherwise, the *can_send_other_messages* and *can_add_web_page_previews* permissions will imply the *can_send_messages*, *can_send_audios*, *can_send_documents*, *can_send_photos*, *can_send_videos*, *can_send_video_notes*, and *can_send_voice_notes* permissions; the *can_send_polls* permission will imply the *can_send_messages* permission.
:param until_date: Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever
:return: instance of method :class:`aiogram.methods.restrict_chat_member.RestrictChatMember`
"""
@ -820,6 +825,7 @@ class Chat(TelegramObject):
chat_id=self.id,
user_id=user_id,
permissions=permissions,
use_independent_chat_permissions=use_independent_chat_permissions,
until_date=until_date,
**kwargs,
)

View file

@ -26,7 +26,7 @@ class ChatAdministratorRights(TelegramObject):
can_restrict_members: bool
""":code:`True`, if the administrator can restrict, ban or unban chat members"""
can_promote_members: bool
""":code:`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 the user)"""
""":code:`True`, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user)"""
can_change_info: bool
""":code:`True`, if the user is allowed to change the chat title, photo and other settings"""
can_invite_users: bool

View file

@ -27,6 +27,8 @@ class ChatJoinRequest(TelegramObject):
"""Chat to which the request was sent"""
from_user: User = Field(..., alias="from")
"""User that sent the join request"""
user_chat_id: int
"""Identifier of a private chat with the user who sent the join request. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user."""
date: datetime.datetime
"""Date the request was sent in Unix time"""
bio: Optional[str] = None

View file

@ -42,7 +42,7 @@ class ChatMember(TelegramObject):
can_restrict_members: Optional[bool] = None
"""*Optional*. :code:`True`, if the administrator can restrict, ban or unban chat members"""
can_promote_members: Optional[bool] = None
"""*Optional*. :code:`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 the user)"""
"""*Optional*. :code:`True`, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user)"""
can_change_info: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to change the chat title, photo and other settings"""
can_invite_users: Optional[bool] = None
@ -58,9 +58,19 @@ class ChatMember(TelegramObject):
is_member: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is a member of the chat at the moment of the request"""
can_send_messages: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send text messages, contacts, locations and venues"""
can_send_media_messages: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes"""
"""*Optional*. :code:`True`, if the user is allowed to send text messages, contacts, invoices, locations and venues"""
can_send_audios: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send audios"""
can_send_documents: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send documents"""
can_send_photos: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send photos"""
can_send_videos: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send videos"""
can_send_video_notes: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send video notes"""
can_send_voice_notes: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send voice notes"""
can_send_polls: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send polls"""
can_send_other_messages: Optional[bool] = None

View file

@ -35,7 +35,7 @@ class ChatMemberAdministrator(ChatMember):
can_restrict_members: bool
""":code:`True`, if the administrator can restrict, ban or unban chat members"""
can_promote_members: bool
""":code:`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 the user)"""
""":code:`True`, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user)"""
can_change_info: bool
""":code:`True`, if the user is allowed to change the chat title, photo and other settings"""
can_invite_users: bool

View file

@ -25,6 +25,26 @@ class ChatMemberRestricted(ChatMember):
"""Information about the user"""
is_member: bool
""":code:`True`, if the user is a member of the chat at the moment of the request"""
can_send_messages: bool
""":code:`True`, if the user is allowed to send text messages, contacts, invoices, locations and venues"""
can_send_audios: bool
""":code:`True`, if the user is allowed to send audios"""
can_send_documents: bool
""":code:`True`, if the user is allowed to send documents"""
can_send_photos: bool
""":code:`True`, if the user is allowed to send photos"""
can_send_videos: bool
""":code:`True`, if the user is allowed to send videos"""
can_send_video_notes: bool
""":code:`True`, if the user is allowed to send video notes"""
can_send_voice_notes: bool
""":code:`True`, if the user is allowed to send voice notes"""
can_send_polls: bool
""":code:`True`, if the user is allowed to send polls"""
can_send_other_messages: bool
""":code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
can_add_web_page_previews: bool
""":code:`True`, if the user is allowed to add web page previews to their messages"""
can_change_info: bool
""":code:`True`, if the user is allowed to change the chat title, photo and other settings"""
can_invite_users: bool
@ -33,15 +53,5 @@ class ChatMemberRestricted(ChatMember):
""":code:`True`, if the user is allowed to pin messages"""
can_manage_topics: bool
""":code:`True`, if the user is allowed to create forum topics"""
can_send_messages: bool
""":code:`True`, if the user is allowed to send text messages, contacts, locations and venues"""
can_send_media_messages: bool
""":code:`True`, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes"""
can_send_polls: bool
""":code:`True`, if the user is allowed to send polls"""
can_send_other_messages: bool
""":code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
can_add_web_page_previews: bool
""":code:`True`, if the user is allowed to add web page previews to their messages"""
until_date: datetime.datetime
"""Date when restrictions will be lifted for this user; unix time. If 0, then the user is restricted forever"""

View file

@ -13,15 +13,25 @@ class ChatPermissions(MutableTelegramObject):
"""
can_send_messages: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send text messages, contacts, locations and venues"""
can_send_media_messages: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages"""
"""*Optional*. :code:`True`, if the user is allowed to send text messages, contacts, invoices, locations and venues"""
can_send_audios: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send audios"""
can_send_documents: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send documents"""
can_send_photos: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send photos"""
can_send_videos: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send videos"""
can_send_video_notes: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send video notes"""
can_send_voice_notes: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send voice notes"""
can_send_polls: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send polls, implies can_send_messages"""
"""*Optional*. :code:`True`, if the user is allowed to send polls"""
can_send_other_messages: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages"""
"""*Optional*. :code:`True`, if the user is allowed to send animations, games, stickers and use inline bots"""
can_add_web_page_previews: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to add web page previews to their messages, implies can_send_media_messages"""
"""*Optional*. :code:`True`, if the user is allowed to add web page previews to their messages"""
can_change_info: Optional[bool] = None
"""*Optional*. :code:`True`, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups"""
can_invite_users: Optional[bool] = None

View file

@ -0,0 +1,14 @@
from aiogram.types import TelegramObject
class ChatShared(TelegramObject):
"""
This object contains information about the chat whose identifier was shared with the bot using a :class:`aiogram.types.keyboard_button_request_chat.KeyboardButtonRequestChat` button.
Source: https://core.telegram.org/bots/api#chatshared
"""
request_id: int
"""Identifier of the request"""
chat_id: int
"""Identifier of the shared chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot may not have access to the chat and could be unable to use this identifier, unless the chat is already known to the bot by some other means."""

View file

@ -6,23 +6,31 @@ from .base import MutableTelegramObject
if TYPE_CHECKING:
from .keyboard_button_poll_type import KeyboardButtonPollType
from .keyboard_button_request_chat import KeyboardButtonRequestChat
from .keyboard_button_request_user import KeyboardButtonRequestUser
from .web_app_info import WebAppInfo
class KeyboardButton(MutableTelegramObject):
"""
This object represents one button of the reply keyboard. For simple text buttons *String* can be used instead of this object to specify text of the button. Optional fields *web_app*, *request_contact*, *request_location*, and *request_poll* are mutually exclusive.
This object represents one button of the reply keyboard. For simple text buttons, *String* can be used instead of this object to specify the button text. The optional fields *web_app*, *request_user*, *request_chat*, *request_contact*, *request_location*, and *request_poll* are mutually exclusive.
**Note:** *request_contact* and *request_location* options will only work in Telegram versions released after 9 April, 2016. Older clients will display *unsupported message*.
**Note:** *request_poll* option will only work in Telegram versions released after 23 January, 2020. Older clients will display *unsupported message*.
**Note:** *web_app* option will only work in Telegram versions released after 16 April, 2022. Older clients will display *unsupported message*.
**Note:** *request_user* and *request_chat* options will only work in Telegram versions released after 3 February, 2023. Older clients will display *unsupported message*.
Source: https://core.telegram.org/bots/api#keyboardbutton
"""
text: str
"""Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed"""
request_user: Optional[KeyboardButtonRequestUser] = None
"""*Optional.* If specified, pressing the button will open a list of suitable users. Tapping on any user will send their identifier to the bot in a 'user_shared' service message. Available in private chats only."""
request_chat: Optional[KeyboardButtonRequestChat] = None
"""*Optional.* If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a 'chat_shared' service message. Available in private chats only."""
request_contact: Optional[bool] = None
"""*Optional*. If :code:`True`, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only."""
request_location: Optional[bool] = None

View file

@ -0,0 +1,33 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from aiogram.types import TelegramObject
if TYPE_CHECKING:
from .chat_administrator_rights import ChatAdministratorRights
class KeyboardButtonRequestChat(TelegramObject):
"""
This object defines the criteria used to request a suitable chat. The identifier of the selected chat will be shared with the bot when the corresponding button is pressed.
Source: https://core.telegram.org/bots/api#keyboardbuttonrequestchat
"""
request_id: int
"""Signed 32-bit identifier of the request, which will be received back in the :class:`aiogram.types.chat_shared.ChatShared` object. Must be unique within the message"""
chat_is_channel: bool
"""Pass :code:`True` to request a channel chat, pass :code:`False` to request a group or a supergroup chat."""
chat_is_forum: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a forum supergroup, pass :code:`False` to request a non-forum chat. If not specified, no additional restrictions are applied."""
chat_has_username: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a supergroup or a channel with a username, pass :code:`False` to request a chat without a username. If not specified, no additional restrictions are applied."""
chat_is_created: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a chat owned by the user. Otherwise, no additional restrictions are applied."""
user_administrator_rights: Optional[ChatAdministratorRights] = None
"""*Optional*. A JSON-serialized object listing the required administrator rights of the user in the chat. The rights must be a superset of *bot_administrator_rights*. If not specified, no additional restrictions are applied."""
bot_administrator_rights: Optional[ChatAdministratorRights] = None
"""*Optional*. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of *user_administrator_rights*. If not specified, no additional restrictions are applied."""
bot_is_member: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a chat with the bot as a member. Otherwise, no additional restrictions are applied."""

View file

@ -0,0 +1,18 @@
from typing import Optional
from aiogram.types import TelegramObject
class KeyboardButtonRequestUser(TelegramObject):
"""
This object defines the criteria used to request a suitable user. The identifier of the selected user will be shared with the bot when the corresponding button is pressed.
Source: https://core.telegram.org/bots/api#keyboardbuttonrequestuser
"""
request_id: int
"""Signed 32-bit identifier of the request, which will be received back in the :class:`aiogram.types.user_shared.UserShared` object. Must be unique within the message"""
user_is_bot: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a bot, pass :code:`False` to request a regular user. If not specified, no additional restrictions are applied."""
user_is_premium: Optional[bool] = None
"""*Optional*. Pass :code:`True` to request a premium user, pass :code:`False` to request a non-premium user. If not specified, no additional restrictions are applied."""

View file

@ -48,6 +48,7 @@ if TYPE_CHECKING:
from .animation import Animation
from .audio import Audio
from .chat import Chat
from .chat_shared import ChatShared
from .contact import Contact
from .dice import Dice
from .document import Document
@ -80,6 +81,7 @@ if TYPE_CHECKING:
from .sticker import Sticker
from .successful_payment import SuccessfulPayment
from .user import User
from .user_shared import UserShared
from .venue import Venue
from .video import Video
from .video_chat_ended import VideoChatEnded
@ -205,6 +207,10 @@ class Message(TelegramObject):
"""*Optional*. Message is an invoice for a `payment <https://core.telegram.org/bots/api#payments>`_, information about the invoice. `More about payments » <https://core.telegram.org/bots/api#payments>`_"""
successful_payment: Optional[SuccessfulPayment] = None
"""*Optional*. Message is a service message about a successful payment, information about the payment. `More about payments » <https://core.telegram.org/bots/api#payments>`_"""
user_shared: Optional[UserShared] = None
"""*Optional*. Service message: a user was shared with the bot"""
chat_shared: Optional[ChatShared] = None
"""*Optional*. Service message: a chat was shared with the bot"""
connected_website: Optional[str] = None
"""*Optional*. The domain name of the website on which the user has logged in. `More about Telegram Login » <https://core.telegram.org/widgets/login>`_"""
write_access_allowed: Optional[WriteAccessAllowed] = None

View file

@ -0,0 +1,14 @@
from aiogram.types import TelegramObject
class UserShared(TelegramObject):
"""
This object contains information about the user whose identifier was shared with the bot using a :class:`aiogram.types.keyboard_button_request_user.KeyboardButtonRequestUser` button.
Source: https://core.telegram.org/bots/api#usershared
"""
request_id: int
"""Identifier of the request"""
user_id: int
"""Identifier of the shared user. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means."""