From 87919ab15d07effaf80c6ec97ca747e6356ae1e3 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:53:21 -0400 Subject: [PATCH 1/2] Add field paid_media to Message and ExternalReplyInfo --- telegram/_message.py | 18 ++++++++++++++++++ telegram/_reply.py | 13 +++++++++++++ telegram/constants.py | 10 ++++++++++ tests/test_constants.py | 2 ++ tests/test_message.py | 5 +++++ tests/test_reply.py | 7 +++++++ 6 files changed, 55 insertions(+) diff --git a/telegram/_message.py b/telegram/_message.py index f5626279a93..cd802160db2 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -52,6 +52,7 @@ from telegram._linkpreviewoptions import LinkPreviewOptions from telegram._messageautodeletetimerchanged import MessageAutoDeleteTimerChanged from telegram._messageentity import MessageEntity +from telegram._paidmedia import PaidMediaInfo from telegram._passport.passportdata import PassportData from telegram._payment.invoice import Invoice from telegram._payment.successfulpayment import SuccessfulPayment @@ -571,6 +572,10 @@ class Message(MaybeInaccessibleMessage): background set. .. versionadded:: 21.2 + paid_media (:obj:`telegram.PaidMediaInfo`, optional): Message contains paid media; + information about the paid media. + + .. versionadded:: NEXT.VERSION Attributes: message_id (:obj:`int`): Unique message identifier inside this chat. @@ -884,6 +889,10 @@ class Message(MaybeInaccessibleMessage): background set .. versionadded:: 21.2 + paid_media (:obj:`telegram.PaidMediaInfo`): Optional. Message contains paid media; + information about the paid media. + + .. versionadded:: NEXT.VERSION .. |custom_emoji_no_md1_support| replace:: Since custom emoji entities are not supported by :attr:`~telegram.constants.ParseMode.MARKDOWN`, this method now raises a @@ -950,6 +959,7 @@ class Message(MaybeInaccessibleMessage): "new_chat_members", "new_chat_photo", "new_chat_title", + "paid_media", "passport_data", "photo", "pinned_message", @@ -1067,6 +1077,7 @@ def __init__( chat_background_set: Optional[ChatBackground] = None, effect_id: Optional[str] = None, show_caption_above_media: Optional[bool] = None, + paid_media: Optional[PaidMediaInfo] = None, *, api_kwargs: Optional[JSONDict] = None, ): @@ -1168,6 +1179,7 @@ def __init__( self.chat_background_set: Optional[ChatBackground] = chat_background_set self.effect_id: Optional[str] = effect_id self.show_caption_above_media: Optional[bool] = show_caption_above_media + self.paid_media: Optional[PaidMediaInfo] = paid_media self._effective_attachment = DEFAULT_NONE @@ -1283,6 +1295,7 @@ def de_json(cls, data: Optional[JSONDict], bot: Optional["Bot"] = None) -> Optio data["users_shared"] = UsersShared.de_json(data.get("users_shared"), bot) data["chat_shared"] = ChatShared.de_json(data.get("chat_shared"), bot) data["chat_background_set"] = ChatBackground.de_json(data.get("chat_background_set"), bot) + data["paid_media"] = PaidMediaInfo.de_json(data.get("paid_media"), bot) # Unfortunately, this needs to be here due to cyclic imports from telegram._giveaway import ( # pylint: disable=import-outside-toplevel @@ -1346,6 +1359,7 @@ def effective_attachment( Location, PassportData, Sequence[PhotoSize], + PaidMediaInfo, Poll, Sticker, Story, @@ -1369,6 +1383,7 @@ def effective_attachment( * :class:`telegram.Location` * :class:`telegram.PassportData` * List[:class:`telegram.PhotoSize`] + * :class:`telegram.PaidMediaInfo` * :class:`telegram.Poll` * :class:`telegram.Sticker` * :class:`telegram.Story` @@ -1386,6 +1401,9 @@ def effective_attachment( :attr:`dice`, :attr:`passport_data` and :attr:`poll` are now also considered to be an attachment. + .. versionchanged:: NEXT.VERSION + :attr:`paid_media` is now also considered to be an attachment. + """ if not isinstance(self._effective_attachment, DefaultValue): return self._effective_attachment diff --git a/telegram/_reply.py b/telegram/_reply.py index 3ca342d067b..6c04847de64 100644 --- a/telegram/_reply.py +++ b/telegram/_reply.py @@ -37,6 +37,7 @@ from telegram._linkpreviewoptions import LinkPreviewOptions from telegram._messageentity import MessageEntity from telegram._messageorigin import MessageOrigin +from telegram._paidmedia import PaidMediaInfo from telegram._payment.invoice import Invoice from telegram._poll import Poll from telegram._story import Story @@ -101,6 +102,10 @@ class ExternalReplyInfo(TelegramObject): poll (:class:`telegram.Poll`, optional): Message is a native poll, information about the poll. venue (:class:`telegram.Venue`, optional): Message is a venue, information about the venue. + paid_media (:class:`telegram.PaidMedia`, optional): Message contains paid media; + information about the paid media. + + .. versionadded:: NEXT.VERSION Attributes: origin (:class:`telegram.MessageOrigin`): Origin of the message replied to by the given @@ -144,6 +149,10 @@ class ExternalReplyInfo(TelegramObject): poll (:class:`telegram.Poll`): Optional. Message is a native poll, information about the poll. venue (:class:`telegram.Venue`): Optional. Message is a venue, information about the venue. + paid_media (:class:`telegram.PaidMedia`): Optional. Message contains paid media; + information about the paid media. + + .. versionadded:: NEXT.VERSION """ __slots__ = ( @@ -162,6 +171,7 @@ class ExternalReplyInfo(TelegramObject): "location", "message_id", "origin", + "paid_media", "photo", "poll", "sticker", @@ -197,6 +207,7 @@ def __init__( location: Optional[Location] = None, poll: Optional[Poll] = None, venue: Optional[Venue] = None, + paid_media: Optional[PaidMediaInfo] = None, *, api_kwargs: Optional[JSONDict] = None, ): @@ -225,6 +236,7 @@ def __init__( self.location: Optional[Location] = location self.poll: Optional[Poll] = poll self.venue: Optional[Venue] = venue + self.paid_media: Optional[PaidMediaInfo] = paid_media self._id_attrs = (self.origin,) @@ -263,6 +275,7 @@ def de_json( data["location"] = Location.de_json(data.get("location"), bot) data["poll"] = Poll.de_json(data.get("poll"), bot) data["venue"] = Venue.de_json(data.get("venue"), bot) + data["paid_media"] = PaidMediaInfo.de_json(data.get("paid_media"), bot) return super().de_json(data=data, bot=bot) diff --git a/telegram/constants.py b/telegram/constants.py index 2131f59db5f..f561eac9790 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -1603,6 +1603,11 @@ class MessageAttachmentType(StringEnum): """:obj:`str`: Messages with :attr:`telegram.Message.invoice`.""" LOCATION = "location" """:obj:`str`: Messages with :attr:`telegram.Message.location`.""" + PAID_MEDIA = "paid_media" + """:obj:`str`: Messages with :attr:`telegram.Message.paid_media`. + + .. versionadded:: NEXT.VERSION + """ PASSPORT_DATA = "passport_data" """:obj:`str`: Messages with :attr:`telegram.Message.passport_data`.""" PHOTO = "photo" @@ -1884,6 +1889,11 @@ class MessageType(StringEnum): """:obj:`str`: Messages with :attr:`telegram.Message.new_chat_title`.""" NEW_CHAT_PHOTO = "new_chat_photo" """:obj:`str`: Messages with :attr:`telegram.Message.new_chat_photo`.""" + PAID_MEDIA = "paid_media" + """:obj:`str`: Messages with :attr:`telegram.Message.paid_media`. + + .. versionadded:: NEXT.VERSION + """ PASSPORT_DATA = "passport_data" """:obj:`str`: Messages with :attr:`telegram.Message.passport_data`.""" PHOTO = "photo" diff --git a/tests/test_constants.py b/tests/test_constants.py index 75368857325..b750f7fba3a 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -216,6 +216,8 @@ def test_message_attachment_type_completeness_reverse(self): name = to_snake_case(match.group(1)) if name == "photo_size": name = "photo" + if name == "paid_media_info": + name = "paid_media" try: constants.MessageAttachmentType(name) except ValueError: diff --git a/tests/test_message.py b/tests/test_message.py index 8bfc632769d..5596710396d 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -46,6 +46,8 @@ MessageAutoDeleteTimerChanged, MessageEntity, MessageOriginChat, + PaidMediaInfo, + PaidMediaPreview, PassportData, PhotoSize, Poll, @@ -275,6 +277,7 @@ def message(bot): {"chat_background_set": ChatBackground(type=BackgroundTypeChatTheme("ice"))}, {"effect_id": "123456789"}, {"show_caption_above_media": True}, + {"paid_media": PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)])}, ], ids=[ "reply", @@ -346,6 +349,7 @@ def message(bot): "chat_background_set", "effect_id", "show_caption_above_media", + "paid_media", ], ) def message_params(bot, request): @@ -1221,6 +1225,7 @@ def test_effective_attachment(self, message_params): "game", "invoice", "location", + "paid_media", "passport_data", "photo", "poll", diff --git a/tests/test_reply.py b/tests/test_reply.py index 4d2c35e8d31..f41ed01eb59 100644 --- a/tests/test_reply.py +++ b/tests/test_reply.py @@ -29,6 +29,8 @@ LinkPreviewOptions, MessageEntity, MessageOriginUser, + PaidMediaInfo, + PaidMediaPreview, ReplyParameters, TextQuote, User, @@ -44,6 +46,7 @@ def external_reply_info(): message_id=TestExternalReplyInfoBase.message_id, link_preview_options=TestExternalReplyInfoBase.link_preview_options, giveaway=TestExternalReplyInfoBase.giveaway, + paid_media=TestExternalReplyInfoBase.paid_media, ) @@ -59,6 +62,7 @@ class TestExternalReplyInfoBase: dtm.datetime.now(dtm.timezone.utc).replace(microsecond=0), 1, ) + paid_media = PaidMediaInfo(5, [PaidMediaPreview(10, 10, 10)]) class TestExternalReplyInfoWithoutRequest(TestExternalReplyInfoBase): @@ -76,6 +80,7 @@ def test_de_json(self, bot): "message_id": self.message_id, "link_preview_options": self.link_preview_options.to_dict(), "giveaway": self.giveaway.to_dict(), + "paid_media": self.paid_media.to_dict(), } external_reply_info = ExternalReplyInfo.de_json(json_dict, bot) @@ -86,6 +91,7 @@ def test_de_json(self, bot): assert external_reply_info.message_id == self.message_id assert external_reply_info.link_preview_options == self.link_preview_options assert external_reply_info.giveaway == self.giveaway + assert external_reply_info.paid_media == self.paid_media assert ExternalReplyInfo.de_json(None, bot) is None @@ -98,6 +104,7 @@ def test_to_dict(self, external_reply_info): assert ext_reply_info_dict["message_id"] == self.message_id assert ext_reply_info_dict["link_preview_options"] == self.link_preview_options.to_dict() assert ext_reply_info_dict["giveaway"] == self.giveaway.to_dict() + assert ext_reply_info_dict["paid_media"] == self.paid_media.to_dict() def test_equality(self, external_reply_info): a = external_reply_info From 7273edea0f0b886c070a0ba960a507b4fa7d153c Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:53:40 -0400 Subject: [PATCH 2/2] Test one more thing in test_stars.py --- tests/test_stars.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_stars.py b/tests/test_stars.py index 25567b30cc0..db53ffb8124 100644 --- a/tests/test_stars.py +++ b/tests/test_stars.py @@ -244,6 +244,7 @@ def test_de_json(self, bot): } st = StarTransaction.de_json(json_dict, bot) st_none = StarTransaction.de_json(None, bot) + assert st.api_kwargs == {} assert st.id == self.id assert st.amount == self.amount assert st.date == from_timestamp(self.date) @@ -329,6 +330,7 @@ def test_de_json(self, bot): } st = StarTransactions.de_json(json_dict, bot) st_none = StarTransactions.de_json(None, bot) + assert st.api_kwargs == {} assert st.transactions == tuple(self.transactions) assert st_none is None
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: