Remove Functionality Deprecated in Bot API 7.3 (#4266)

This commit is contained in:
Harshil 2024-05-29 13:59:23 -04:00 committed by GitHub
parent 6ba7a097f4
commit c1c5438f37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 709 additions and 1275 deletions

View file

@ -46,6 +46,7 @@ PRIVATE_BASE_CLASSES = {
"_BaseThumbedMedium": "TelegramObject", "_BaseThumbedMedium": "TelegramObject",
"_BaseMedium": "TelegramObject", "_BaseMedium": "TelegramObject",
"_CredentialsBase": "TelegramObject", "_CredentialsBase": "TelegramObject",
"_ChatBase": "TelegramObject",
} }

View file

@ -1,6 +1,8 @@
Chat Chat
==== ====
.. Also lists methods of _ChatBase, but not the ones of TelegramObject
.. autoclass:: telegram.Chat .. autoclass:: telegram.Chat
:members: :members:
:show-inheritance: :show-inheritance:
:inherited-members: TelegramObject

View file

@ -1,6 +1,8 @@
ChatFullInfo ChatFullInfo
============ ============
.. Also lists methods of _ChatBase, but not the ones of TelegramObject
.. autoclass:: telegram.ChatFullInfo .. autoclass:: telegram.ChatFullInfo
:members: :members:
:show-inheritance: :show-inheritance:
:inherited-members: TelegramObject

View file

@ -1,6 +1,6 @@
PhotoSize PhotoSize
========= =========
.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject .. Also lists methods of _BaseMedium, but not the ones of TelegramObject
.. autoclass:: telegram.PhotoSize .. autoclass:: telegram.PhotoSize
:members: :members:

View file

@ -1152,7 +1152,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
Note: Note:
Since the release of Bot API 5.5 it can be impossible to forward messages from Since the release of Bot API 5.5 it can be impossible to forward messages from
some chats. Use the attributes :attr:`telegram.Message.has_protected_content` and some chats. Use the attributes :attr:`telegram.Message.has_protected_content` and
:attr:`telegram.Chat.has_protected_content` to check this. :attr:`telegram.ChatFullInfo.has_protected_content` to check this.
As a workaround, it is still possible to use :meth:`copy_message`. However, this As a workaround, it is still possible to use :meth:`copy_message`. However, this
behaviour is undocumented and might be changed by Telegram. behaviour is undocumented and might be changed by Telegram.
@ -4610,8 +4610,8 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
) -> bool: ) -> bool:
"""Use this method to set a new group sticker set for a supergroup. """Use this method to set a new group sticker set for a supergroup.
The bot must be an administrator in the chat for this to work and must have the appropriate The bot must be an administrator in the chat for this to work and must have the appropriate
admin rights. Use the field :attr:`telegram.Chat.can_set_sticker_set` optionally returned admin rights. Use the field :attr:`telegram.ChatFullInfo.can_set_sticker_set` optionally
in :meth:`get_chat` requests to check if the bot can use this method. returned in :meth:`get_chat` requests to check if the bot can use this method.
Args: Args:
chat_id (:obj:`int` | :obj:`str`): |chat_id_group| chat_id (:obj:`int` | :obj:`str`): |chat_id_group|
@ -4644,7 +4644,7 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
) -> bool: ) -> bool:
"""Use this method to delete a group sticker set from a supergroup. The bot must be an """Use this method to delete a group sticker set from a supergroup. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights. administrator in the chat for this to work and must have the appropriate admin rights.
Use the field :attr:`telegram.Chat.can_set_sticker_set` optionally returned in Use the field :attr:`telegram.ChatFullInfo.can_set_sticker_set` optionally returned in
:meth:`get_chat` requests to check if the bot can use this method. :meth:`get_chat` requests to check if the bot can use this method.
Args: Args:

File diff suppressed because it is too large Load diff

View file

@ -19,58 +19,380 @@
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChatFullInfo.""" """This module contains an object that represents a Telegram ChatFullInfo."""
from datetime import datetime from datetime import datetime
from typing import TYPE_CHECKING, Optional, Sequence from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._birthdate import Birthdate from telegram._birthdate import Birthdate
from telegram._chat import Chat from telegram._chat import Chat, _ChatBase
from telegram._chatlocation import ChatLocation from telegram._chatlocation import ChatLocation
from telegram._chatpermissions import ChatPermissions from telegram._chatpermissions import ChatPermissions
from telegram._files.chatphoto import ChatPhoto from telegram._files.chatphoto import ChatPhoto
from telegram._reaction import ReactionType from telegram._reaction import ReactionType
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
from telegram._utils.types import JSONDict from telegram._utils.types import JSONDict
if TYPE_CHECKING: if TYPE_CHECKING:
from telegram import BusinessIntro, BusinessLocation, BusinessOpeningHours, Message from telegram import Bot, BusinessIntro, BusinessLocation, BusinessOpeningHours, Message
class ChatFullInfo(Chat): class ChatFullInfo(_ChatBase):
""" """
This object contains full information about a chat. This object contains full information about a chat.
Objects of this class are comparable in terms of equality. Two objects of this class are Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`~telegram.Chat.id` is equal. considered equal, if their :attr:`~telegram.Chat.id` is equal.
Caution:
This class is a subclass of :class:`telegram.Chat` and inherits all attributes and methods
for backwards compatibility. In the future, this class will *NOT* inherit from
:class:`telegram.Chat`.
.. seealso::
All arguments and attributes can be found in :class:`telegram.Chat`.
.. versionadded:: 21.2 .. versionadded:: 21.2
.. versionchanged:: NEXT.VERSION
Explicit support for all shortcut methods known from :class:`telegram.Chat` on this
object. Previously those were only available because this class inherited from
:class:`telegram.Chat`.
Args: Args:
id (:obj:`int`): Unique identifier for this chat.
type (:obj:`str`): Type of chat, can be either :attr:`PRIVATE`, :attr:`GROUP`,
:attr:`SUPERGROUP` or :attr:`CHANNEL`.
accent_color_id (:obj:`int`, optional): Identifier of the
:class:`accent color <telegram.constants.AccentColor>` for the chat name and
backgrounds of the chat photo, reply header, and link preview. See `accent colors`_
for more details.
.. versionadded:: 20.8
max_reaction_count (:obj:`int`): The maximum number of reactions that can be set on a max_reaction_count (:obj:`int`): The maximum number of reactions that can be set on a
message in the chat. message in the chat.
.. versionadded:: 21.2 .. versionadded:: 21.2
title (:obj:`str`, optional): Title, for supergroups, channels and group chats.
username (:obj:`str`, optional): Username, for private chats, supergroups and channels if
available.
first_name (:obj:`str`, optional): First name of the other party in a private chat.
last_name (:obj:`str`, optional): Last name of the other party in a private chat.
is_forum (:obj:`bool`, optional): :obj:`True`, if the supergroup chat is a forum
(has topics_ enabled).
.. versionadded:: 20.0
photo (:class:`telegram.ChatPhoto`, optional): Chat photo.
active_usernames (Sequence[:obj:`str`], optional): If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels.
.. versionadded:: 20.0
birthdate (:obj:`telegram.Birthdate`, optional): For private chats,
the date of birth of the user.
.. versionadded:: 21.1
business_intro (:class:`telegram.BusinessIntro`, optional): For private chats with
business accounts, the intro of the business.
.. versionadded:: 21.1
business_location (:class:`telegram.BusinessLocation`, optional): For private chats with
business accounts, the location of the business.
.. versionadded:: 21.1
business_opening_hours (:class:`telegram.BusinessOpeningHours`, optional): For private
chats with business accounts, the opening hours of the business.
.. versionadded:: 21.1
personal_chat (:obj:`telegram.Chat`, optional): For private chats, the personal channel of
the user.
.. versionadded:: 21.1
available_reactions (Sequence[:class:`telegram.ReactionType`], optional): List of available
reactions allowed in the chat. If omitted, then all of
:const:`telegram.constants.ReactionEmoji` are allowed.
.. versionadded:: 20.8
background_custom_emoji_id (:obj:`str`, optional): Custom emoji identifier of emoji chosen
by the chat for the reply header and link preview background.
.. versionadded:: 20.8
profile_accent_color_id (:obj:`int`, optional): Identifier of the
:class:`accent color <telegram.constants.ProfileAccentColor>` for the chat's profile
background. See profile `accent colors`_ for more details.
.. versionadded:: 20.8
profile_background_custom_emoji_id (:obj:`str`, optional): Custom emoji identifier of
the emoji chosen by the chat for its profile background.
.. versionadded:: 20.8
emoji_status_custom_emoji_id (:obj:`str`, optional): Custom emoji identifier of emoji
status of the chat or the other party in a private chat.
.. versionadded:: 20.0
emoji_status_expiration_date (:class:`datetime.datetime`, optional): Expiration date of
emoji status of the chat or the other party in a private chat, in seconds.
|datetime_localization|
.. versionadded:: 20.5
bio (:obj:`str`, optional): Bio of the other party in a private chat.
has_private_forwards (:obj:`bool`, optional): :obj:`True`, 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.
.. versionadded:: 13.9
has_restricted_voice_and_video_messages (:obj:`bool`, optional): :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat.
.. versionadded:: 20.0
join_to_send_messages (:obj:`bool`, optional): :obj:`True`, if users need to join the
supergroup before they can send messages.
.. versionadded:: 20.0
join_by_request (:obj:`bool`, optional): :obj:`True`, if all users directly joining the
supergroup without using an invite link need to be approved by supergroup
administrators.
.. versionadded:: 20.0
description (:obj:`str`, optional): Description, for groups, supergroups and channel chats.
invite_link (:obj:`str`, optional): Primary invite link, for groups, supergroups and
channel.
pinned_message (:class:`telegram.Message`, optional): The most recent pinned message
(by sending date).
permissions (:class:`telegram.ChatPermissions`): Optional. Default chat member permissions,
for groups and supergroups.
slow_mode_delay (:obj:`int`, optional): For supergroups, the minimum allowed delay between
consecutive messages sent by each unprivileged user.
unrestrict_boost_count (:obj:`int`, 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.
.. versionadded:: 21.0
message_auto_delete_time (:obj:`int`, optional): The time after which all messages sent to
the chat will be automatically deleted; in seconds.
.. versionadded:: 13.4
has_aggressive_anti_spam_enabled (:obj:`bool`, optional): :obj:`True`, if aggressive
anti-spam checks are enabled in the supergroup. The field is only available to chat
administrators.
.. versionadded:: 20.0
has_hidden_members (:obj:`bool`, optional): :obj:`True`, if non-administrators can only
get the list of bots and administrators in the chat.
.. versionadded:: 20.0
has_protected_content (:obj:`bool`, optional): :obj:`True`, if messages from the chat can't
be forwarded to other chats.
.. versionadded:: 13.9
has_visible_history (:obj:`bool`, optional): :obj:`True`, if new chat members will have
access to old messages; available only to chat administrators.
.. versionadded:: 20.8
sticker_set_name (:obj:`str`, optional): For supergroups, name of group sticker set.
can_set_sticker_set (:obj:`bool`, optional): :obj:`True`, if the bot can change group the
sticker set.
custom_emoji_sticker_set_name (:obj:`str`, optional): For supergroups, the name of the
group's custom emoji sticker set. Custom emoji from this set can be used by all users
and bots in the group.
.. versionadded:: 21.0
linked_chat_id (:obj:`int`, optional): Unique identifier for the linked chat, i.e. the
discussion group identifier for a channel and vice versa; for supergroups and channel
chats.
location (:class:`telegram.ChatLocation`, optional): For supergroups, the location to which
the supergroup is connected.
Attributes: Attributes:
id (:obj:`int`): Unique identifier for this chat.
type (:obj:`str`): Type of chat, can be either :attr:`PRIVATE`, :attr:`GROUP`,
:attr:`SUPERGROUP` or :attr:`CHANNEL`.
accent_color_id (:obj:`int`): Optional. Identifier of the
:class:`accent color <telegram.constants.AccentColor>` for the chat name and
backgrounds of the chat photo, reply header, and link preview. See `accent colors`_
for more details.
.. versionadded:: 20.8
max_reaction_count (:obj:`int`): The maximum number of reactions that can be set on a max_reaction_count (:obj:`int`): The maximum number of reactions that can be set on a
message in the chat. message in the chat.
.. versionadded:: 21.2 .. versionadded:: 21.2
title (:obj:`str`, optional): Title, for supergroups, channels and group chats.
username (:obj:`str`, optional): Username, for private chats, supergroups and channels if
available.
first_name (:obj:`str`, optional): First name of the other party in a private chat.
last_name (:obj:`str`, optional): Last name of the other party in a private chat.
is_forum (:obj:`bool`, optional): :obj:`True`, if the supergroup chat is a forum
(has topics_ enabled).
.. versionadded:: 20.0
photo (:class:`telegram.ChatPhoto`): Optional. Chat photo.
active_usernames (Tuple[:obj:`str`]): Optional. If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels.
This list is empty if the chat has no active usernames or this chat instance was not
obtained via :meth:`~telegram.Bot.get_chat`.
.. versionadded:: 20.0
birthdate (:obj:`telegram.Birthdate`): Optional. For private chats,
the date of birth of the user.
.. versionadded:: 21.1
business_intro (:class:`telegram.BusinessIntro`): Optional. For private chats with
business accounts, the intro of the business.
.. versionadded:: 21.1
business_location (:class:`telegram.BusinessLocation`): Optional. For private chats with
business accounts, the location of the business.
.. versionadded:: 21.1
business_opening_hours (:class:`telegram.BusinessOpeningHours`): Optional. For private
chats with business accounts, the opening hours of the business.
.. versionadded:: 21.1
personal_chat (:obj:`telegram.Chat`): Optional. For private chats, the personal channel of
the user.
.. versionadded:: 21.1
available_reactions (Tuple[:class:`telegram.ReactionType`]): Optional. List of available
reactions allowed in the chat. If omitted, then all of
:const:`telegram.constants.ReactionEmoji` are allowed.
.. versionadded:: 20.8
background_custom_emoji_id (:obj:`str`): Optional. Custom emoji identifier of emoji chosen
by the chat for the reply header and link preview background.
.. versionadded:: 20.8
profile_accent_color_id (:obj:`int`): Optional. Identifier of the
:class:`accent color <telegram.constants.ProfileAccentColor>` for the chat's profile
background. See profile `accent colors`_ for more details.
.. versionadded:: 20.8
profile_background_custom_emoji_id (:obj:`str`): Optional. Custom emoji identifier of
the emoji chosen by the chat for its profile background.
.. versionadded:: 20.8
emoji_status_custom_emoji_id (:obj:`str`): Optional. Custom emoji identifier of emoji
status of the chat or the other party in a private chat.
.. versionadded:: 20.0
emoji_status_expiration_date (:class:`datetime.datetime`): Optional. Expiration date of
emoji status of the chat or the other party in a private chat, in seconds.
|datetime_localization|
.. versionadded:: 20.5
bio (:obj:`str`): Optional. Bio of the other party in a private chat.
has_private_forwards (:obj:`bool`): Optional. :obj:`True`, 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.
.. versionadded:: 13.9
has_restricted_voice_and_video_messages (:obj:`bool`): Optional. :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat.
.. versionadded:: 20.0
join_to_send_messages (:obj:`bool`): Optional. :obj:`True`, if users need to join
the supergroup before they can send messages.
.. versionadded:: 20.0
join_by_request (:obj:`bool`): Optional. :obj:`True`, if all users directly joining the
supergroup without using an invite link need to be approved by supergroup
administrators.
.. versionadded:: 20.0
description (:obj:`str`): Optional. Description, for groups, supergroups and channel chats.
invite_link (:obj:`str`): Optional. Primary invite link, for groups, supergroups and
channel.
pinned_message (:class:`telegram.Message`): Optional. The most recent pinned message
(by sending date).
permissions (:class:`telegram.ChatPermissions`): Optional. Default chat member permissions,
for groups and supergroups.
slow_mode_delay (:obj:`int`): Optional. For supergroups, the minimum allowed delay between
consecutive messages sent by each unprivileged user.
unrestrict_boost_count (:obj:`int`): 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.
.. versionadded:: 21.0
message_auto_delete_time (:obj:`int`): Optional. The time after which all messages sent to
the chat will be automatically deleted; in seconds.
.. versionadded:: 13.4
has_aggressive_anti_spam_enabled (:obj:`bool`): Optional. :obj:`True`, if aggressive
anti-spam checks are enabled in the supergroup. The field is only available to chat
administrators.
.. versionadded:: 20.0
has_hidden_members (:obj:`bool`): Optional. :obj:`True`, if non-administrators can only
get the list of bots and administrators in the chat.
.. versionadded:: 20.0
has_protected_content (:obj:`bool`): Optional. :obj:`True`, if messages from the chat can't
be forwarded to other chats.
.. versionadded:: 13.9
has_visible_history (:obj:`bool`): Optional. :obj:`True`, if new chat members will have
access to old messages; available only to chat administrators.
.. versionadded:: 20.8
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
can_set_sticker_set (:obj:`bool`): Optional. :obj:`True`, if the bot can change group the
sticker set.
custom_emoji_sticker_set_name (:obj:`str`): Optional. For supergroups, the name of the
group's custom emoji sticker set. Custom emoji from this set can be used by all users
and bots in the group.
.. versionadded:: 21.0
linked_chat_id (:obj:`int`): Optional. Unique identifier for the linked chat, i.e. the
discussion group identifier for a channel and vice versa; for supergroups and channel
chats.
location (:class:`telegram.ChatLocation`): Optional. For supergroups, the location to which
the supergroup is connected.
.. _accent colors: https://core.telegram.org/bots/api#accent-colors
.. _topics: https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups
""" """
__slots__ = ("max_reaction_count",) __slots__ = (
"accent_color_id",
"active_usernames",
"available_reactions",
"background_custom_emoji_id",
"bio",
"birthdate",
"business_intro",
"business_location",
"business_opening_hours",
"can_set_sticker_set",
"custom_emoji_sticker_set_name",
"description",
"emoji_status_custom_emoji_id",
"emoji_status_expiration_date",
"has_aggressive_anti_spam_enabled",
"has_hidden_members",
"has_private_forwards",
"has_protected_content",
"has_restricted_voice_and_video_messages",
"has_visible_history",
"invite_link",
"join_by_request",
"join_to_send_messages",
"linked_chat_id",
"location",
"max_reaction_count",
"message_auto_delete_time",
"permissions",
"personal_chat",
"photo",
"pinned_message",
"profile_accent_color_id",
"profile_background_custom_emoji_id",
"slow_mode_delay",
"sticker_set_name",
"unrestrict_boost_count",
)
def __init__( def __init__(
self, self,
id: int, id: int,
type: str, type: str,
accent_color_id: int, # API 7.3 made this argument required accent_color_id: int,
max_reaction_count: int, # NEW arg in api 7.3 and is required max_reaction_count: int,
title: Optional[str] = None, title: Optional[str] = None,
username: Optional[str] = None, username: Optional[str] = None,
first_name: Optional[str] = None, first_name: Optional[str] = None,
@ -120,47 +442,93 @@ class ChatFullInfo(Chat):
username=username, username=username,
first_name=first_name, first_name=first_name,
last_name=last_name, last_name=last_name,
photo=photo,
description=description,
invite_link=invite_link,
pinned_message=pinned_message,
permissions=permissions,
sticker_set_name=sticker_set_name,
can_set_sticker_set=can_set_sticker_set,
slow_mode_delay=slow_mode_delay,
bio=bio,
linked_chat_id=linked_chat_id,
location=location,
message_auto_delete_time=message_auto_delete_time,
has_private_forwards=has_private_forwards,
has_protected_content=has_protected_content,
join_to_send_messages=join_to_send_messages,
join_by_request=join_by_request,
has_restricted_voice_and_video_messages=has_restricted_voice_and_video_messages,
is_forum=is_forum, is_forum=is_forum,
active_usernames=active_usernames,
emoji_status_custom_emoji_id=emoji_status_custom_emoji_id,
emoji_status_expiration_date=emoji_status_expiration_date,
has_aggressive_anti_spam_enabled=has_aggressive_anti_spam_enabled,
has_hidden_members=has_hidden_members,
available_reactions=available_reactions,
accent_color_id=accent_color_id,
background_custom_emoji_id=background_custom_emoji_id,
profile_accent_color_id=profile_accent_color_id,
profile_background_custom_emoji_id=profile_background_custom_emoji_id,
has_visible_history=has_visible_history,
unrestrict_boost_count=unrestrict_boost_count,
custom_emoji_sticker_set_name=custom_emoji_sticker_set_name,
birthdate=birthdate,
personal_chat=personal_chat,
business_intro=business_intro,
business_location=business_location,
business_opening_hours=business_opening_hours,
api_kwargs=api_kwargs, api_kwargs=api_kwargs,
) )
# Required and unique to this class- # Required and unique to this class-
with self._unfrozen(): with self._unfrozen():
self.max_reaction_count: int = max_reaction_count self.max_reaction_count: int = max_reaction_count
self.photo: Optional[ChatPhoto] = photo
self.bio: Optional[str] = bio
self.has_private_forwards: Optional[bool] = has_private_forwards
self.description: Optional[str] = description
self.invite_link: Optional[str] = invite_link
self.pinned_message: Optional[Message] = pinned_message
self.permissions: Optional[ChatPermissions] = permissions
self.slow_mode_delay: Optional[int] = slow_mode_delay
self.message_auto_delete_time: Optional[int] = (
int(message_auto_delete_time) if message_auto_delete_time is not None else None
)
self.has_protected_content: Optional[bool] = has_protected_content
self.has_visible_history: Optional[bool] = has_visible_history
self.sticker_set_name: Optional[str] = sticker_set_name
self.can_set_sticker_set: Optional[bool] = can_set_sticker_set
self.linked_chat_id: Optional[int] = linked_chat_id
self.location: Optional[ChatLocation] = location
self.join_to_send_messages: Optional[bool] = join_to_send_messages
self.join_by_request: Optional[bool] = join_by_request
self.has_restricted_voice_and_video_messages: Optional[bool] = (
has_restricted_voice_and_video_messages
)
self.active_usernames: Tuple[str, ...] = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id: Optional[str] = emoji_status_custom_emoji_id
self.emoji_status_expiration_date: Optional[datetime] = emoji_status_expiration_date
self.has_aggressive_anti_spam_enabled: Optional[bool] = (
has_aggressive_anti_spam_enabled
)
self.has_hidden_members: Optional[bool] = has_hidden_members
self.available_reactions: Optional[Tuple[ReactionType, ...]] = parse_sequence_arg(
available_reactions
)
self.accent_color_id: Optional[int] = accent_color_id
self.background_custom_emoji_id: Optional[str] = background_custom_emoji_id
self.profile_accent_color_id: Optional[int] = profile_accent_color_id
self.profile_background_custom_emoji_id: Optional[str] = (
profile_background_custom_emoji_id
)
self.unrestrict_boost_count: Optional[int] = unrestrict_boost_count
self.custom_emoji_sticker_set_name: Optional[str] = custom_emoji_sticker_set_name
self.birthdate: Optional[Birthdate] = birthdate
self.personal_chat: Optional["Chat"] = personal_chat
self.business_intro: Optional["BusinessIntro"] = business_intro
self.business_location: Optional["BusinessLocation"] = business_location
self.business_opening_hours: Optional["BusinessOpeningHours"] = business_opening_hours
self._freeze() @classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatFullInfo"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
data = cls._parse_data(data)
if not data:
return None
# Get the local timezone from the bot if it has defaults
loc_tzinfo = extract_tzinfo_from_defaults(bot)
data["emoji_status_expiration_date"] = from_timestamp(
data.get("emoji_status_expiration_date"), tzinfo=loc_tzinfo
)
data["photo"] = ChatPhoto.de_json(data.get("photo"), bot)
from telegram import ( # pylint: disable=import-outside-toplevel
BusinessIntro,
BusinessLocation,
BusinessOpeningHours,
Message,
)
data["pinned_message"] = Message.de_json(data.get("pinned_message"), bot)
data["permissions"] = ChatPermissions.de_json(data.get("permissions"), bot)
data["location"] = ChatLocation.de_json(data.get("location"), bot)
data["available_reactions"] = ReactionType.de_list(data.get("available_reactions"), bot)
data["birthdate"] = Birthdate.de_json(data.get("birthdate"), bot)
data["personal_chat"] = Chat.de_json(data.get("personal_chat"), bot)
data["business_intro"] = BusinessIntro.de_json(data.get("business_intro"), bot)
data["business_location"] = BusinessLocation.de_json(data.get("business_location"), bot)
data["business_opening_hours"] = BusinessOpeningHours.de_json(
data.get("business_opening_hours"), bot
)
return super().de_json(data=data, bot=bot)

View file

@ -3331,7 +3331,7 @@ class Message(MaybeInaccessibleMessage):
Note: Note:
Since the release of Bot API 5.5 it can be impossible to forward messages from Since the release of Bot API 5.5 it can be impossible to forward messages from
some chats. Use the attributes :attr:`telegram.Message.has_protected_content` and some chats. Use the attributes :attr:`telegram.Message.has_protected_content` and
:attr:`telegram.Chat.has_protected_content` to check this. :attr:`telegram.ChatFullInfo.has_protected_content` to check this.
As a workaround, it is still possible to use :meth:`copy`. However, this As a workaround, it is still possible to use :meth:`copy`. However, this
behaviour is undocumented and might be changed by Telegram. behaviour is undocumented and might be changed by Telegram.

View file

@ -168,7 +168,8 @@ ZERO_DATE: Final[datetime.datetime] = datetime.datetime(1970, 1, 1, tzinfo=UTC)
class AccentColor(Enum): class AccentColor(Enum):
"""This enum contains the available accent colors for :class:`telegram.Chat.accent_color_id`. """This enum contains the available accent colors for
:class:`telegram.ChatFullInfo.accent_color_id`.
The members of this enum are named tuples with the following attributes: The members of this enum are named tuples with the following attributes:
- ``identifier`` (:obj:`int`): The identifier of the accent color. - ``identifier`` (:obj:`int`): The identifier of the accent color.
@ -1959,7 +1960,7 @@ class PollingLimit(IntEnum):
class ProfileAccentColor(Enum): class ProfileAccentColor(Enum):
"""This enum contains the available accent colors for """This enum contains the available accent colors for
:class:`telegram.Chat.profile_accent_color_id`. :class:`telegram.ChatFullInfo.profile_accent_color_id`.
The members of this enum are named tuples with the following attributes: The members of this enum are named tuples with the following attributes:
- ``identifier`` (:obj:`int`): The identifier of the accent color. - ``identifier`` (:obj:`int`): The identifier of the accent color.

View file

@ -17,31 +17,12 @@
# You should have received a copy of the GNU Lesser Public License # You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import datetime
import warnings
import pytest import pytest
from telegram import ( from telegram import Bot, Chat, ChatPermissions, ReactionTypeEmoji, User
Birthdate,
Bot,
BusinessIntro,
BusinessLocation,
BusinessOpeningHours,
BusinessOpeningHoursInterval,
Chat,
ChatLocation,
ChatPermissions,
Location,
ReactionTypeCustomEmoji,
ReactionTypeEmoji,
User,
)
from telegram._chat import _deprecated_attrs
from telegram._utils.datetime import UTC, to_timestamp
from telegram.constants import ChatAction, ChatType, ReactionEmoji from telegram.constants import ChatAction, ChatType, ReactionEmoji
from telegram.helpers import escape_markdown from telegram.helpers import escape_markdown
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.bot_method_checks import ( from tests.auxil.bot_method_checks import (
check_defaults_handling, check_defaults_handling,
check_shortcut_call, check_shortcut_call,
@ -57,37 +38,7 @@ def chat(bot):
title=TestChatBase.title, title=TestChatBase.title,
type=TestChatBase.type_, type=TestChatBase.type_,
username=TestChatBase.username, username=TestChatBase.username,
sticker_set_name=TestChatBase.sticker_set_name,
can_set_sticker_set=TestChatBase.can_set_sticker_set,
permissions=TestChatBase.permissions,
slow_mode_delay=TestChatBase.slow_mode_delay,
bio=TestChatBase.bio,
linked_chat_id=TestChatBase.linked_chat_id,
location=TestChatBase.location,
has_private_forwards=True,
has_protected_content=True,
has_visible_history=True,
join_to_send_messages=True,
join_by_request=True,
has_restricted_voice_and_video_messages=True,
is_forum=True, is_forum=True,
active_usernames=TestChatBase.active_usernames,
emoji_status_custom_emoji_id=TestChatBase.emoji_status_custom_emoji_id,
emoji_status_expiration_date=TestChatBase.emoji_status_expiration_date,
has_aggressive_anti_spam_enabled=TestChatBase.has_aggressive_anti_spam_enabled,
has_hidden_members=TestChatBase.has_hidden_members,
available_reactions=TestChatBase.available_reactions,
accent_color_id=TestChatBase.accent_color_id,
background_custom_emoji_id=TestChatBase.background_custom_emoji_id,
profile_accent_color_id=TestChatBase.profile_accent_color_id,
profile_background_custom_emoji_id=TestChatBase.profile_background_custom_emoji_id,
unrestrict_boost_count=TestChatBase.unrestrict_boost_count,
custom_emoji_sticker_set_name=TestChatBase.custom_emoji_sticker_set_name,
business_intro=TestChatBase.business_intro,
business_location=TestChatBase.business_location,
business_opening_hours=TestChatBase.business_opening_hours,
birthdate=Birthdate(1, 1),
personal_chat=TestChatBase.personal_chat,
first_name=TestChatBase.first_name, first_name=TestChatBase.first_name,
last_name=TestChatBase.last_name, last_name=TestChatBase.last_name,
) )
@ -101,48 +52,7 @@ class TestChatBase:
title = "ToledosPalaceBot - Group" title = "ToledosPalaceBot - Group"
type_ = "group" type_ = "group"
username = "username" username = "username"
all_members_are_administrators = False
sticker_set_name = "stickers"
can_set_sticker_set = False
permissions = ChatPermissions(
can_send_messages=True,
can_change_info=False,
can_invite_users=True,
)
slow_mode_delay = 30
bio = "I'm a Barbie Girl in a Barbie World"
linked_chat_id = 11880
location = ChatLocation(Location(123, 456), "Barbie World")
has_protected_content = True
has_visible_history = True
has_private_forwards = True
join_to_send_messages = True
join_by_request = True
has_restricted_voice_and_video_messages = True
is_forum = True is_forum = True
active_usernames = ["These", "Are", "Usernames!"]
emoji_status_custom_emoji_id = "VeryUniqueCustomEmojiID"
emoji_status_expiration_date = datetime.datetime.now(tz=UTC).replace(microsecond=0)
has_aggressive_anti_spam_enabled = True
has_hidden_members = True
available_reactions = [
ReactionTypeEmoji(ReactionEmoji.THUMBS_DOWN),
ReactionTypeCustomEmoji("custom_emoji_id"),
]
business_intro = BusinessIntro("Title", "Description", None)
business_location = BusinessLocation("Address", Location(123, 456))
business_opening_hours = BusinessOpeningHours(
"Country/City",
[BusinessOpeningHoursInterval(opening, opening + 60) for opening in (0, 24 * 60)],
)
accent_color_id = 1
background_custom_emoji_id = "background_custom_emoji_id"
profile_accent_color_id = 2
profile_background_custom_emoji_id = "profile_background_custom_emoji_id"
unrestrict_boost_count = 100
custom_emoji_sticker_set_name = "custom_emoji_sticker_set_name"
birthdate = Birthdate(1, 1)
personal_chat = Chat(3, "private", "private")
first_name = "first" first_name = "first"
last_name = "last" last_name = "last"
@ -159,40 +69,7 @@ class TestChatWithoutRequest(TestChatBase):
"title": self.title, "title": self.title,
"type": self.type_, "type": self.type_,
"username": self.username, "username": self.username,
"all_members_are_administrators": self.all_members_are_administrators,
"sticker_set_name": self.sticker_set_name,
"can_set_sticker_set": self.can_set_sticker_set,
"permissions": self.permissions.to_dict(),
"slow_mode_delay": self.slow_mode_delay,
"bio": self.bio,
"business_intro": self.business_intro.to_dict(),
"business_location": self.business_location.to_dict(),
"business_opening_hours": self.business_opening_hours.to_dict(),
"has_protected_content": self.has_protected_content,
"has_visible_history": self.has_visible_history,
"has_private_forwards": self.has_private_forwards,
"linked_chat_id": self.linked_chat_id,
"location": self.location.to_dict(),
"join_to_send_messages": self.join_to_send_messages,
"join_by_request": self.join_by_request,
"has_restricted_voice_and_video_messages": (
self.has_restricted_voice_and_video_messages
),
"is_forum": self.is_forum, "is_forum": self.is_forum,
"active_usernames": self.active_usernames,
"emoji_status_custom_emoji_id": self.emoji_status_custom_emoji_id,
"emoji_status_expiration_date": to_timestamp(self.emoji_status_expiration_date),
"has_aggressive_anti_spam_enabled": self.has_aggressive_anti_spam_enabled,
"has_hidden_members": self.has_hidden_members,
"available_reactions": [reaction.to_dict() for reaction in self.available_reactions],
"accent_color_id": self.accent_color_id,
"background_custom_emoji_id": self.background_custom_emoji_id,
"profile_accent_color_id": self.profile_accent_color_id,
"profile_background_custom_emoji_id": self.profile_background_custom_emoji_id,
"unrestrict_boost_count": self.unrestrict_boost_count,
"custom_emoji_sticker_set_name": self.custom_emoji_sticker_set_name,
"birthdate": self.birthdate.to_dict(),
"personal_chat": self.personal_chat.to_dict(),
"first_name": self.first_name, "first_name": self.first_name,
"last_name": self.last_name, "last_name": self.last_name,
} }
@ -202,76 +79,10 @@ class TestChatWithoutRequest(TestChatBase):
assert chat.title == self.title assert chat.title == self.title
assert chat.type == self.type_ assert chat.type == self.type_
assert chat.username == self.username assert chat.username == self.username
assert chat.sticker_set_name == self.sticker_set_name
assert chat.can_set_sticker_set == self.can_set_sticker_set
assert chat.permissions == self.permissions
assert chat.slow_mode_delay == self.slow_mode_delay
assert chat.bio == self.bio
assert chat.business_intro == self.business_intro
assert chat.business_location == self.business_location
assert chat.business_opening_hours == self.business_opening_hours
assert chat.has_protected_content == self.has_protected_content
assert chat.has_visible_history == self.has_visible_history
assert chat.has_private_forwards == self.has_private_forwards
assert chat.linked_chat_id == self.linked_chat_id
assert chat.location.location == self.location.location
assert chat.location.address == self.location.address
assert chat.join_to_send_messages == self.join_to_send_messages
assert chat.join_by_request == self.join_by_request
assert (
chat.has_restricted_voice_and_video_messages
== self.has_restricted_voice_and_video_messages
)
assert chat.api_kwargs == {
"all_members_are_administrators": self.all_members_are_administrators
}
assert chat.is_forum == self.is_forum assert chat.is_forum == self.is_forum
assert chat.active_usernames == tuple(self.active_usernames)
assert chat.emoji_status_custom_emoji_id == self.emoji_status_custom_emoji_id
assert chat.emoji_status_expiration_date == (self.emoji_status_expiration_date)
assert chat.has_aggressive_anti_spam_enabled == self.has_aggressive_anti_spam_enabled
assert chat.has_hidden_members == self.has_hidden_members
assert chat.available_reactions == tuple(self.available_reactions)
assert chat.accent_color_id == self.accent_color_id
assert chat.background_custom_emoji_id == self.background_custom_emoji_id
assert chat.profile_accent_color_id == self.profile_accent_color_id
assert chat.profile_background_custom_emoji_id == self.profile_background_custom_emoji_id
assert chat.unrestrict_boost_count == self.unrestrict_boost_count
assert chat.custom_emoji_sticker_set_name == self.custom_emoji_sticker_set_name
assert chat.birthdate == self.birthdate
assert chat.personal_chat == self.personal_chat
assert chat.first_name == self.first_name assert chat.first_name == self.first_name
assert chat.last_name == self.last_name assert chat.last_name == self.last_name
def test_de_json_localization(self, bot, raw_bot, tz_bot):
json_dict = {
"id": self.id_,
"type": self.type_,
"emoji_status_expiration_date": to_timestamp(self.emoji_status_expiration_date),
}
chat_bot = Chat.de_json(json_dict, bot)
chat_bot_raw = Chat.de_json(json_dict, raw_bot)
chat_bot_tz = Chat.de_json(json_dict, tz_bot)
# comparing utcoffsets because comparing tzinfo objects is not reliable
emoji_expire_offset = chat_bot_tz.emoji_status_expiration_date.utcoffset()
emoji_expire_offset_tz = tz_bot.defaults.tzinfo.utcoffset(
chat_bot_tz.emoji_status_expiration_date.replace(tzinfo=None)
)
assert chat_bot.emoji_status_expiration_date.tzinfo == UTC
assert chat_bot_raw.emoji_status_expiration_date.tzinfo == UTC
assert emoji_expire_offset_tz == emoji_expire_offset
def test_always_tuples_attributes(self):
chat = Chat(
id=123,
title="title",
type=Chat.PRIVATE,
)
assert isinstance(chat.active_usernames, tuple)
assert chat.active_usernames == ()
def test_to_dict(self, chat): def test_to_dict(self, chat):
chat_dict = chat.to_dict() chat_dict = chat.to_dict()
@ -280,67 +91,10 @@ class TestChatWithoutRequest(TestChatBase):
assert chat_dict["title"] == chat.title assert chat_dict["title"] == chat.title
assert chat_dict["type"] == chat.type assert chat_dict["type"] == chat.type
assert chat_dict["username"] == chat.username assert chat_dict["username"] == chat.username
assert chat_dict["permissions"] == chat.permissions.to_dict()
assert chat_dict["slow_mode_delay"] == chat.slow_mode_delay
assert chat_dict["bio"] == chat.bio
assert chat_dict["business_intro"] == chat.business_intro.to_dict()
assert chat_dict["business_location"] == chat.business_location.to_dict()
assert chat_dict["business_opening_hours"] == chat.business_opening_hours.to_dict()
assert chat_dict["has_private_forwards"] == chat.has_private_forwards
assert chat_dict["has_protected_content"] == chat.has_protected_content
assert chat_dict["has_visible_history"] == chat.has_visible_history
assert chat_dict["linked_chat_id"] == chat.linked_chat_id
assert chat_dict["location"] == chat.location.to_dict()
assert chat_dict["join_to_send_messages"] == chat.join_to_send_messages
assert chat_dict["join_by_request"] == chat.join_by_request
assert (
chat_dict["has_restricted_voice_and_video_messages"]
== chat.has_restricted_voice_and_video_messages
)
assert chat_dict["is_forum"] == chat.is_forum assert chat_dict["is_forum"] == chat.is_forum
assert chat_dict["active_usernames"] == list(chat.active_usernames)
assert chat_dict["emoji_status_custom_emoji_id"] == chat.emoji_status_custom_emoji_id
assert chat_dict["emoji_status_expiration_date"] == to_timestamp(
chat.emoji_status_expiration_date
)
assert (
chat_dict["has_aggressive_anti_spam_enabled"] == chat.has_aggressive_anti_spam_enabled
)
assert chat_dict["has_hidden_members"] == chat.has_hidden_members
assert chat_dict["available_reactions"] == [
reaction.to_dict() for reaction in chat.available_reactions
]
assert chat_dict["accent_color_id"] == chat.accent_color_id
assert chat_dict["background_custom_emoji_id"] == chat.background_custom_emoji_id
assert chat_dict["profile_accent_color_id"] == chat.profile_accent_color_id
assert (
chat_dict["profile_background_custom_emoji_id"]
== chat.profile_background_custom_emoji_id
)
assert chat_dict["custom_emoji_sticker_set_name"] == chat.custom_emoji_sticker_set_name
assert chat_dict["unrestrict_boost_count"] == chat.unrestrict_boost_count
assert chat_dict["birthdate"] == chat.birthdate.to_dict()
assert chat_dict["personal_chat"] == chat.personal_chat.to_dict()
assert chat_dict["first_name"] == chat.first_name assert chat_dict["first_name"] == chat.first_name
assert chat_dict["last_name"] == chat.last_name assert chat_dict["last_name"] == chat.last_name
def test_deprecated_attributes(self, chat):
for depr_attr in _deprecated_attrs:
with pytest.warns(PTBDeprecationWarning, match="deprecated and will only be accessib"):
getattr(chat, depr_attr)
with warnings.catch_warnings(): # No warning should be raised
warnings.simplefilter("error")
chat.id
chat.first_name
def test_deprecated_arguments(self):
for depr_attr in _deprecated_attrs:
with pytest.warns(PTBDeprecationWarning, match="deprecated and will only be availabl"):
Chat(1, "type", **{depr_attr: "1"})
with warnings.catch_warnings(): # No warning should be raised
warnings.simplefilter("error")
Chat(1, "type", first_name="first_name")
def test_enum_init(self): def test_enum_init(self):
chat = Chat(id=1, type="foo") chat = Chat(id=1, type="foo")
assert chat.type == "foo" assert chat.type == "foo"

View file

@ -17,7 +17,6 @@
# You should have received a copy of the GNU Lesser Public License # You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import datetime import datetime
import warnings
import pytest import pytest
@ -35,7 +34,6 @@ from telegram import (
ReactionTypeCustomEmoji, ReactionTypeCustomEmoji,
ReactionTypeEmoji, ReactionTypeEmoji,
) )
from telegram._chat import _deprecated_attrs
from telegram._utils.datetime import UTC, to_timestamp from telegram._utils.datetime import UTC, to_timestamp
from telegram.constants import ReactionEmoji from telegram.constants import ReactionEmoji
from tests.auxil.slots import mro_slots from tests.auxil.slots import mro_slots
@ -44,19 +42,19 @@ from tests.auxil.slots import mro_slots
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def chat_full_info(bot): def chat_full_info(bot):
chat = ChatFullInfo( chat = ChatFullInfo(
TestChatInfoBase.id_, TestChatFullInfoBase.id_,
type=TestChatInfoBase.type_, type=TestChatFullInfoBase.type_,
accent_color_id=TestChatInfoBase.accent_color_id, accent_color_id=TestChatFullInfoBase.accent_color_id,
max_reaction_count=TestChatInfoBase.max_reaction_count, max_reaction_count=TestChatFullInfoBase.max_reaction_count,
title=TestChatInfoBase.title, title=TestChatFullInfoBase.title,
username=TestChatInfoBase.username, username=TestChatFullInfoBase.username,
sticker_set_name=TestChatInfoBase.sticker_set_name, sticker_set_name=TestChatFullInfoBase.sticker_set_name,
can_set_sticker_set=TestChatInfoBase.can_set_sticker_set, can_set_sticker_set=TestChatFullInfoBase.can_set_sticker_set,
permissions=TestChatInfoBase.permissions, permissions=TestChatFullInfoBase.permissions,
slow_mode_delay=TestChatInfoBase.slow_mode_delay, slow_mode_delay=TestChatFullInfoBase.slow_mode_delay,
bio=TestChatInfoBase.bio, bio=TestChatFullInfoBase.bio,
linked_chat_id=TestChatInfoBase.linked_chat_id, linked_chat_id=TestChatFullInfoBase.linked_chat_id,
location=TestChatInfoBase.location, location=TestChatFullInfoBase.location,
has_private_forwards=True, has_private_forwards=True,
has_protected_content=True, has_protected_content=True,
has_visible_history=True, has_visible_history=True,
@ -64,35 +62,37 @@ def chat_full_info(bot):
join_by_request=True, join_by_request=True,
has_restricted_voice_and_video_messages=True, has_restricted_voice_and_video_messages=True,
is_forum=True, is_forum=True,
active_usernames=TestChatInfoBase.active_usernames, active_usernames=TestChatFullInfoBase.active_usernames,
emoji_status_custom_emoji_id=TestChatInfoBase.emoji_status_custom_emoji_id, emoji_status_custom_emoji_id=TestChatFullInfoBase.emoji_status_custom_emoji_id,
emoji_status_expiration_date=TestChatInfoBase.emoji_status_expiration_date, emoji_status_expiration_date=TestChatFullInfoBase.emoji_status_expiration_date,
has_aggressive_anti_spam_enabled=TestChatInfoBase.has_aggressive_anti_spam_enabled, has_aggressive_anti_spam_enabled=TestChatFullInfoBase.has_aggressive_anti_spam_enabled,
has_hidden_members=TestChatInfoBase.has_hidden_members, has_hidden_members=TestChatFullInfoBase.has_hidden_members,
available_reactions=TestChatInfoBase.available_reactions, available_reactions=TestChatFullInfoBase.available_reactions,
background_custom_emoji_id=TestChatInfoBase.background_custom_emoji_id, background_custom_emoji_id=TestChatFullInfoBase.background_custom_emoji_id,
profile_accent_color_id=TestChatInfoBase.profile_accent_color_id, profile_accent_color_id=TestChatFullInfoBase.profile_accent_color_id,
profile_background_custom_emoji_id=TestChatInfoBase.profile_background_custom_emoji_id, profile_background_custom_emoji_id=TestChatFullInfoBase.profile_background_custom_emoji_id,
unrestrict_boost_count=TestChatInfoBase.unrestrict_boost_count, unrestrict_boost_count=TestChatFullInfoBase.unrestrict_boost_count,
custom_emoji_sticker_set_name=TestChatInfoBase.custom_emoji_sticker_set_name, custom_emoji_sticker_set_name=TestChatFullInfoBase.custom_emoji_sticker_set_name,
business_intro=TestChatInfoBase.business_intro, business_intro=TestChatFullInfoBase.business_intro,
business_location=TestChatInfoBase.business_location, business_location=TestChatFullInfoBase.business_location,
business_opening_hours=TestChatInfoBase.business_opening_hours, business_opening_hours=TestChatFullInfoBase.business_opening_hours,
birthdate=Birthdate(1, 1), birthdate=Birthdate(1, 1),
personal_chat=TestChatInfoBase.personal_chat, personal_chat=TestChatFullInfoBase.personal_chat,
first_name="first_name",
last_name="last_name",
) )
chat.set_bot(bot) chat.set_bot(bot)
chat._unfreeze() chat._unfreeze()
return chat return chat
class TestChatInfoBase: # Shortcut methods are tested in test_chat.py.
class TestChatFullInfoBase:
id_ = -28767330 id_ = -28767330
max_reaction_count = 2 max_reaction_count = 2
title = "ToledosPalaceBot - Group" title = "ToledosPalaceBot - Group"
type_ = "group" type_ = "group"
username = "username" username = "username"
all_members_are_administrators = False
sticker_set_name = "stickers" sticker_set_name = "stickers"
can_set_sticker_set = False can_set_sticker_set = False
permissions = ChatPermissions( permissions = ChatPermissions(
@ -134,13 +134,16 @@ class TestChatInfoBase:
custom_emoji_sticker_set_name = "custom_emoji_sticker_set_name" custom_emoji_sticker_set_name = "custom_emoji_sticker_set_name"
birthdate = Birthdate(1, 1) birthdate = Birthdate(1, 1)
personal_chat = Chat(3, "private", "private") personal_chat = Chat(3, "private", "private")
first_name = "first_name"
last_name = "last_name"
class TestChatWithoutRequest(TestChatInfoBase): class TestChatFullInfoWithoutRequest(TestChatFullInfoBase):
def test_slot_behaviour(self, chat_full_info): def test_slot_behaviour(self, chat_full_info):
cfi = chat_full_info cfi = chat_full_info
for attr in cfi.__slots__: for attr in cfi.__slots__:
assert getattr(cfi, attr, "err") != "err", f"got extra slot '{attr}'" assert getattr(cfi, attr, "err") != "err", f"got extra slot '{attr}'"
assert len(mro_slots(cfi)) == len(set(mro_slots(cfi))), "duplicate slot" assert len(mro_slots(cfi)) == len(set(mro_slots(cfi))), "duplicate slot"
def test_de_json(self, bot): def test_de_json(self, bot):
@ -151,7 +154,6 @@ class TestChatWithoutRequest(TestChatInfoBase):
"accent_color_id": self.accent_color_id, "accent_color_id": self.accent_color_id,
"max_reaction_count": self.max_reaction_count, "max_reaction_count": self.max_reaction_count,
"username": self.username, "username": self.username,
"all_members_are_administrators": self.all_members_are_administrators,
"sticker_set_name": self.sticker_set_name, "sticker_set_name": self.sticker_set_name,
"can_set_sticker_set": self.can_set_sticker_set, "can_set_sticker_set": self.can_set_sticker_set,
"permissions": self.permissions.to_dict(), "permissions": self.permissions.to_dict(),
@ -184,26 +186,134 @@ class TestChatWithoutRequest(TestChatInfoBase):
"custom_emoji_sticker_set_name": self.custom_emoji_sticker_set_name, "custom_emoji_sticker_set_name": self.custom_emoji_sticker_set_name,
"birthdate": self.birthdate.to_dict(), "birthdate": self.birthdate.to_dict(),
"personal_chat": self.personal_chat.to_dict(), "personal_chat": self.personal_chat.to_dict(),
"first_name": self.first_name,
"last_name": self.last_name,
} }
cfi = ChatFullInfo.de_json(json_dict, bot) cfi = ChatFullInfo.de_json(json_dict, bot)
assert cfi.id == self.id_
assert cfi.title == self.title
assert cfi.type == self.type_
assert cfi.username == self.username
assert cfi.sticker_set_name == self.sticker_set_name
assert cfi.can_set_sticker_set == self.can_set_sticker_set
assert cfi.permissions == self.permissions
assert cfi.slow_mode_delay == self.slow_mode_delay
assert cfi.bio == self.bio
assert cfi.business_intro == self.business_intro
assert cfi.business_location == self.business_location
assert cfi.business_opening_hours == self.business_opening_hours
assert cfi.has_protected_content == self.has_protected_content
assert cfi.has_visible_history == self.has_visible_history
assert cfi.has_private_forwards == self.has_private_forwards
assert cfi.linked_chat_id == self.linked_chat_id
assert cfi.location.location == self.location.location
assert cfi.location.address == self.location.address
assert cfi.join_to_send_messages == self.join_to_send_messages
assert cfi.join_by_request == self.join_by_request
assert (
cfi.has_restricted_voice_and_video_messages
== self.has_restricted_voice_and_video_messages
)
assert cfi.is_forum == self.is_forum
assert cfi.active_usernames == tuple(self.active_usernames)
assert cfi.emoji_status_custom_emoji_id == self.emoji_status_custom_emoji_id
assert cfi.emoji_status_expiration_date == (self.emoji_status_expiration_date)
assert cfi.has_aggressive_anti_spam_enabled == self.has_aggressive_anti_spam_enabled
assert cfi.has_hidden_members == self.has_hidden_members
assert cfi.available_reactions == tuple(self.available_reactions)
assert cfi.accent_color_id == self.accent_color_id
assert cfi.background_custom_emoji_id == self.background_custom_emoji_id
assert cfi.profile_accent_color_id == self.profile_accent_color_id
assert cfi.profile_background_custom_emoji_id == self.profile_background_custom_emoji_id
assert cfi.unrestrict_boost_count == self.unrestrict_boost_count
assert cfi.custom_emoji_sticker_set_name == self.custom_emoji_sticker_set_name
assert cfi.birthdate == self.birthdate
assert cfi.personal_chat == self.personal_chat
assert cfi.first_name == self.first_name
assert cfi.last_name == self.last_name
assert cfi.max_reaction_count == self.max_reaction_count assert cfi.max_reaction_count == self.max_reaction_count
def test_de_json_localization(self, bot, raw_bot, tz_bot):
json_dict = {
"id": self.id_,
"type": self.type_,
"accent_color_id": self.accent_color_id,
"max_reaction_count": self.max_reaction_count,
"emoji_status_expiration_date": to_timestamp(self.emoji_status_expiration_date),
}
cfi_bot = ChatFullInfo.de_json(json_dict, bot)
cfi_bot_raw = ChatFullInfo.de_json(json_dict, raw_bot)
cfi_bot_tz = ChatFullInfo.de_json(json_dict, tz_bot)
# comparing utcoffsets because comparing tzinfo objects is not reliable
emoji_expire_offset = cfi_bot_tz.emoji_status_expiration_date.utcoffset()
emoji_expire_offset_tz = tz_bot.defaults.tzinfo.utcoffset(
cfi_bot_tz.emoji_status_expiration_date.replace(tzinfo=None)
)
assert cfi_bot.emoji_status_expiration_date.tzinfo == UTC
assert cfi_bot_raw.emoji_status_expiration_date.tzinfo == UTC
assert emoji_expire_offset_tz == emoji_expire_offset
def test_to_dict(self, chat_full_info): def test_to_dict(self, chat_full_info):
cfi = chat_full_info cfi = chat_full_info
cfi_dict = cfi.to_dict() cfi_dict = cfi.to_dict()
assert isinstance(cfi_dict, dict) assert isinstance(cfi_dict, dict)
assert cfi_dict["id"] == cfi.id
assert cfi_dict["title"] == cfi.title
assert cfi_dict["type"] == cfi.type
assert cfi_dict["username"] == cfi.username
assert cfi_dict["permissions"] == cfi.permissions.to_dict()
assert cfi_dict["slow_mode_delay"] == cfi.slow_mode_delay
assert cfi_dict["bio"] == cfi.bio
assert cfi_dict["business_intro"] == cfi.business_intro.to_dict()
assert cfi_dict["business_location"] == cfi.business_location.to_dict()
assert cfi_dict["business_opening_hours"] == cfi.business_opening_hours.to_dict()
assert cfi_dict["has_private_forwards"] == cfi.has_private_forwards
assert cfi_dict["has_protected_content"] == cfi.has_protected_content
assert cfi_dict["has_visible_history"] == cfi.has_visible_history
assert cfi_dict["linked_chat_id"] == cfi.linked_chat_id
assert cfi_dict["location"] == cfi.location.to_dict()
assert cfi_dict["join_to_send_messages"] == cfi.join_to_send_messages
assert cfi_dict["join_by_request"] == cfi.join_by_request
assert (
cfi_dict["has_restricted_voice_and_video_messages"]
== cfi.has_restricted_voice_and_video_messages
)
assert cfi_dict["is_forum"] == cfi.is_forum
assert cfi_dict["active_usernames"] == list(cfi.active_usernames)
assert cfi_dict["emoji_status_custom_emoji_id"] == cfi.emoji_status_custom_emoji_id
assert cfi_dict["emoji_status_expiration_date"] == to_timestamp(
cfi.emoji_status_expiration_date
)
assert cfi_dict["has_aggressive_anti_spam_enabled"] == cfi.has_aggressive_anti_spam_enabled
assert cfi_dict["has_hidden_members"] == cfi.has_hidden_members
assert cfi_dict["available_reactions"] == [
reaction.to_dict() for reaction in cfi.available_reactions
]
assert cfi_dict["accent_color_id"] == cfi.accent_color_id
assert cfi_dict["background_custom_emoji_id"] == cfi.background_custom_emoji_id
assert cfi_dict["profile_accent_color_id"] == cfi.profile_accent_color_id
assert (
cfi_dict["profile_background_custom_emoji_id"]
== cfi.profile_background_custom_emoji_id
)
assert cfi_dict["custom_emoji_sticker_set_name"] == cfi.custom_emoji_sticker_set_name
assert cfi_dict["unrestrict_boost_count"] == cfi.unrestrict_boost_count
assert cfi_dict["birthdate"] == cfi.birthdate.to_dict()
assert cfi_dict["personal_chat"] == cfi.personal_chat.to_dict()
assert cfi_dict["first_name"] == cfi.first_name
assert cfi_dict["last_name"] == cfi.last_name
assert cfi_dict["max_reaction_count"] == cfi.max_reaction_count assert cfi_dict["max_reaction_count"] == cfi.max_reaction_count
def test_attr_access_no_warning(self, chat_full_info): def test_always_tuples_attributes(self):
cfi = chat_full_info cfi = ChatFullInfo(
for depr_attr in _deprecated_attrs: id=123,
with warnings.catch_warnings(): # No warning should be raised type=Chat.PRIVATE,
warnings.simplefilter("error") accent_color_id=1,
getattr(cfi, depr_attr) max_reaction_count=2,
)
def test_cfi_creation_no_warning(self, chat_full_info): assert isinstance(cfi.active_usernames, tuple)
cfi = chat_full_info assert cfi.active_usernames == ()
with warnings.catch_warnings():
dict = cfi.to_dict()
ChatFullInfo(**dict)

View file

@ -20,7 +20,6 @@
from telegram import Animation, Audio, Document, PhotoSize, Sticker, Video, VideoNote, Voice from telegram import Animation, Audio, Document, PhotoSize, Sticker, Video, VideoNote, Voice
from telegram._chat import _deprecated_attrs
from tests.test_official.helpers import _get_params_base from tests.test_official.helpers import _get_params_base
IGNORED_OBJECTS = ("ResponseParameters",) IGNORED_OBJECTS = ("ResponseParameters",)
@ -173,9 +172,7 @@ def ignored_param_requirements(object_name: str) -> set[str]:
# Arguments that are optional arguments for now for backwards compatibility # Arguments that are optional arguments for now for backwards compatibility
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = { BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}
"Chat": set(_deprecated_attrs), # removed by bot api 7.3
}
def backwards_compat_kwargs(object_name: str) -> set[str]: def backwards_compat_kwargs(object_name: str) -> set[str]:

View file

@ -342,10 +342,14 @@ class TestTelegramObject:
chat = (await pp.get_chat_data())[1] chat = (await pp.get_chat_data())[1]
assert chat.id == 1 assert chat.id == 1
assert chat.type == Chat.PRIVATE assert chat.type == Chat.PRIVATE
assert chat.api_kwargs == { api_kwargs_expected = {
"all_members_are_administrators": True, "all_members_are_administrators": True,
"something": "Manually inserted", "something": "Manually inserted",
} }
# There are older attrs in Chat's api_kwargs which are present but we don't care about them
for k, v in api_kwargs_expected.items():
assert chat.api_kwargs[k] == v
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
# removed attribute should not be available as attribute, only though api_kwargs # removed attribute should not be available as attribute, only though api_kwargs
chat.all_members_are_administrators chat.all_members_are_administrators