Skip to content

Commit

Permalink
Split out the class ChatFullInfo from the class Chat and changed the …
Browse files Browse the repository at this point in the history
…return type of the method getChat to ChatFullInfo. Added the field max_reaction_count to the class ChatFullInfo.
  • Loading branch information
Badiboy committed May 11, 2024
1 parent 9a3d048 commit 3532812
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
6 changes: 3 additions & 3 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None,
)


def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
def get_chat(self, chat_id: Union[int, str]) -> types.ChatFullInfo:
"""
Use this method to get up to date information about the chat (current name of the user for one-on-one
conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
Expand All @@ -1504,9 +1504,9 @@ def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
:type chat_id: :obj:`int` or :obj:`str`
:return: Chat information
:rtype: :class:`telebot.types.Chat`
:rtype: :class:`telebot.types.ChatFullInfo`
"""
return types.Chat.de_json(
return types.ChatFullInfo.de_json(
apihelper.get_chat(self.token, chat_id)
)

Expand Down
4 changes: 2 additions & 2 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,10 +1527,10 @@ def send_invoice(
:param provider_data: 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.
:param timeout:
:param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency.
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.
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. 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.
:param protect_content: Protects the contents of the sent message from forwarding and saving
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
:param reply_parameters: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
:return:
"""
method_url = r'sendInvoice'
Expand Down
6 changes: 3 additions & 3 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ async def get_user_profile_photos(self, user_id: int, offset: Optional[int]=None
result = await asyncio_helper.get_user_profile_photos(self.token, user_id, offset, limit)
return types.UserProfilePhotos.de_json(result)

async def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
async def get_chat(self, chat_id: Union[int, str]) -> types.ChatFullInfo:
"""
Use this method to get up to date information about the chat (current name of the user for one-on-one
conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
Expand All @@ -2900,10 +2900,10 @@ async def get_chat(self, chat_id: Union[int, str]) -> types.Chat:
:type chat_id: :obj:`int` or :obj:`str`
:return: Chat information
:rtype: :class:`telebot.types.Chat`
:rtype: :class:`telebot.types.ChatFullInfo`
"""
result = await asyncio_helper.get_chat(self.token, chat_id)
return types.Chat.de_json(result)
return types.ChatFullInfo.de_json(result)

async def leave_chat(self, chat_id: Union[int, str]) -> bool:
"""
Expand Down
87 changes: 40 additions & 47 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def __init__(self, id, title, **kwargs):


# noinspection PyShadowingBuiltins
class Chat(JsonDeserializable):
class ChatFullInfo(JsonDeserializable):
"""
This object represents a chat.
Expand Down Expand Up @@ -594,11 +594,13 @@ class Chat(JsonDeserializable):
:param is_forum: Optional. True, if the supergroup chat is a forum (has topics enabled)
:type is_forum: :obj:`bool`
:param max_reaction_count: Optional. The maximum number of reactions that can be set on a message in the chat
:type max_reaction_count: :obj:`int`
:param photo: Optional. Chat photo. Returned only in getChat.
:type photo: :class:`telebot.types.ChatPhoto`
:param active_usernames: Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels.
Returned only in getChat.
:param active_usernames: Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat.
:type active_usernames: :obj:`list` of :obj:`str`
:param birthdate: Optional. Birthdate of the other party in a private chat. Returned only in getChat.
Expand All @@ -616,100 +618,80 @@ class Chat(JsonDeserializable):
:param personal_chat: Optional. For private chats, the personal channel of the user. Returned only in getChat.
:type personal_chat: :class:`telebot.types.Chat`
:param available_reactions: Optional. List of available chat reactions; for private chats, supergroups and channels.
Returned only in getChat.
:param available_reactions: Optional. List of available chat reactions; for private chats, supergroups and channels. Returned only in getChat.
:type available_reactions: :obj:`list` of :class:`telebot.types.ReactionType`
:param accent_color_id: Optional. Optional. Identifier of the accent color for the chat name and backgrounds of the chat photo,
reply header, and link preview. See accent colors for more details. Returned only in getChat. Always returned in getChat.
:type accent_color_id: :obj:`int`
:param background_custom_emoji_id: Optional. Custom emoji identifier of emoji chosen by the chat for the reply header
and link preview background. Returned only in getChat.
:param background_custom_emoji_id: Optional. Custom emoji identifier of emoji chosen by the chat for the reply header and link preview background. Returned only in getChat.
:type background_custom_emoji_id: :obj:`str`
:param profile_accent_color_id: Optional. Identifier of the accent color for the chat's profile background.
See profile accent colors for more details. Returned only in getChat.
:param profile_accent_color_id: Optional. Identifier of the accent color for the chat's profile background. See profile accent colors for more details. Returned only in getChat.
:type profile_accent_color_id: :obj:`int`
:param profile_background_custom_emoji_id: Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background.
Returned only in getChat.
:param profile_background_custom_emoji_id: Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background. Returned only in getChat.
:type profile_background_custom_emoji_id: :obj:`str`
:param emoji_status_custom_emoji_id: Optional. Custom emoji identifier of emoji status of the other party in a private chat.
Returned only in getChat.
:param emoji_status_custom_emoji_id: Optional. Custom emoji identifier of emoji status of the other party in a private chat. Returned only in getChat.
:type emoji_status_custom_emoji_id: :obj:`str`
:param emoji_status_expiration_date: Optional. Expiration date of the emoji status of the other party in a private chat,
if any. Returned only in getChat.
:param emoji_status_expiration_date: Optional. Expiration date of the emoji status of the other party in a private chat, if any. Returned only in getChat.
:type emoji_status_expiration_date: :obj:`int`
:param bio: Optional. Bio of the other party in a private chat. Returned only in getChat.
:type bio: :obj:`str`
:param has_private_forwards: Optional. :obj:`bool`, if privacy settings of the other party in the private chat
allows to use tg://user?id=<user_id> links only in chats with the user. Returned only in getChat.
:param has_private_forwards: Optional. :obj:`bool`, if privacy settings of the other party in the private chat allows to use tg://user?id=<user_id> links only in chats with the user. Returned only in getChat.
:type has_private_forwards: :obj:`bool`
:param has_restricted_voice_and_video_messages: Optional. True, if the privacy settings of the other party restrict sending voice and video note messages
in the private chat. Returned only in getChat.
:param has_restricted_voice_and_video_messages: Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat.
:type :obj:`bool`
:param join_to_send_messages: Optional. :obj:`bool`, if users need to join the supergroup before they can send
messages. Returned only in getChat.
:param join_to_send_messages: Optional. :obj:`bool`, if users need to join the supergroup before they can send messages. Returned only in getChat.
:type join_to_send_messages: :obj:`bool`
:param join_by_request: Optional. :obj:`bool`, if all users directly joining the supergroup need to be approved
by supergroup administrators. Returned only in getChat.
:param join_by_request: Optional. :obj:`bool`, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat.
:type join_by_request: :obj:`bool`
:param description: Optional. Description, for groups, supergroups and channel chats. Returned only in getChat.
:type description: :obj:`str`
:param invite_link: Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in
getChat.
:param invite_link: Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat.
:type invite_link: :obj:`str`
:param pinned_message: Optional. The most recent pinned message (by sending date). Returned only in getChat.
:type pinned_message: :class:`telebot.types.Message`
:param permissions: Optional. Default chat member permissions, for groups and supergroups. Returned only in
getChat.
:param permissions: Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
:type permissions: :class:`telebot.types.ChatPermissions`
:param slow_mode_delay: Optional. For supergroups, the minimum allowed delay between consecutive messages sent
by each unpriviledged user; in seconds. Returned only in getChat.
:param slow_mode_delay: Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds. Returned only in getChat.
:type slow_mode_delay: :obj:`int`
:param unrestrict_boost_count: Optional. For supergroups, the minimum number of boosts that a non-administrator
user needs to add in order to ignore slow mode and chat permissions. Returned only in getChat.
:param unrestrict_boost_count: Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions. Returned only in getChat.
:type unrestrict_boost_count: :obj:`int`
:param message_auto_delete_time: Optional. The time after which all messages sent to the chat will be
automatically deleted; in seconds. Returned only in getChat.
:param message_auto_delete_time: Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
:type message_auto_delete_time: :obj:`int`
:param has_aggressive_anti_spam_enabled: Optional. :obj:`bool`, if the chat has enabled aggressive anti-spam
protection. Returned only in getChat.
:param has_aggressive_anti_spam_enabled: Optional. :obj:`bool`, if the chat has enabled aggressive anti-spam protection. Returned only in getChat.
:type has_aggressive_anti_spam_enabled: :obj:`bool`
:param has_hidden_members: Optional. :obj:`bool`, if the chat has enabled hidden members. Returned only in
getChat.
:param has_hidden_members: Optional. :obj:`bool`, if the chat has enabled hidden members. Returned only in getChat.
:type has_hidden_members: :obj:`bool`
:param has_protected_content: Optional. :obj:`bool`, if messages from the chat can't be forwarded to other
chats. Returned only in getChat.
:param has_protected_content: Optional. :obj:`bool`, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
:type has_protected_content: :obj:`bool`
:param has_visible_history: Optional. True, if new chat members will have access to old messages;
available only to chat administrators. Returned only in getChat.
:param has_visible_history: Optional. True, if new chat members will have access to old messages; available only to chat administrators. Returned only in getChat.
:type has_visible_history: :obj:`bool`
:param sticker_set_name: Optional. For supergroups, name of group sticker set. Returned only in getChat.
:type sticker_set_name: :obj:`str`
:param can_set_sticker_set: Optional. :obj:`bool`, if the bot can change the group sticker set. Returned only in
getChat.
:param can_set_sticker_set: Optional. :obj:`bool`, if the bot can change the group sticker set. Returned only in getChat.
:type can_set_sticker_set: :obj:`bool`
:param custom_emoji_sticker_set_name: Optional. For supergroups, the name of the group's custom emoji sticker set.
Expand All @@ -722,12 +704,11 @@ class Chat(JsonDeserializable):
signed 64 bit integer or double-precision float type are safe for storing this identifier. Returned only in getChat.
:type linked_chat_id: :obj:`int`
:param location: Optional. For supergroups, the location to which the supergroup is connected. Returned only in
getChat.
:param location: Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
:type location: :class:`telebot.types.ChatLocation`
:return: Instance of the class
:rtype: :class:`telebot.types.Chat`
:rtype: :class:`telebot.types.ChatFullInfo`
"""
@classmethod
def de_json(cls, json_string):
Expand Down Expand Up @@ -762,7 +743,7 @@ def __init__(self, id, type, title=None, username=None, first_name=None,
message_auto_delete_time=None, has_protected_content=None, sticker_set_name=None,
can_set_sticker_set=None, linked_chat_id=None, location=None,
join_to_send_messages=None, join_by_request=None, has_restricted_voice_and_video_messages=None,
is_forum=None, active_usernames=None, emoji_status_custom_emoji_id=None,
is_forum=None, max_reaction_count=None, active_usernames=None, emoji_status_custom_emoji_id=None,
has_hidden_members=None, has_aggressive_anti_spam_enabled=None, emoji_status_expiration_date=None,
available_reactions=None, accent_color_id=None, background_custom_emoji_id=None, profile_accent_color_id=None,
profile_background_custom_emoji_id=None, has_visible_history=None,
Expand All @@ -775,6 +756,7 @@ def __init__(self, id, type, title=None, username=None, first_name=None,
self.first_name: str = first_name
self.last_name: str = last_name
self.is_forum: bool = is_forum
self.max_reaction_count: int = max_reaction_count
self.photo: ChatPhoto = photo
self.bio: str = bio
self.join_to_send_messages: bool = join_to_send_messages
Expand Down Expand Up @@ -812,6 +794,17 @@ def __init__(self, id, type, title=None, username=None, first_name=None,
self.birthdate: Birthdate = birthdate


class Chat(ChatFullInfo):
"""
In BotAPI 7.3 Chat was reduced and full info moved to ChatFullInfo:
"Split out the class ChatFullInfo from the class Chat and changed the return type of the method getChat to ChatFullInfo."
https://core.telegram.org/bots/api#chatfullinfo
Currently Chat is left as full copy of ChatFullInfo for compatibility.
"""
pass


class MessageID(JsonDeserializable):
"""
Expand Down

0 comments on commit 3532812

Please sign in to comment.