Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/unreleased/5078.FoNwUYLbXQFRebTFhR6UPn.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pull_requests = [
{ uid = "5078", author_uid = "aelkheir", closes_threads = ["5077"] },
{ uid = "5079", author_uid = "aelkheir" },
{ uid = "5085", author_uids = ["Bibo-Joshi"] },
{ uid = "5089", author_uids = ["Bibo-Joshi"] },
]
16 changes: 15 additions & 1 deletion src/telegram/_gifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ class AcceptedGiftTypes(TelegramObject):

Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal if their :attr:`unlimited_gifts`, :attr:`limited_gifts`,
:attr:`unique_gifts` and :attr:`premium_subscription` are equal.
:attr:`unique_gifts`, :attr:`premium_subscription` and :attr:`gifts_from_channels` are equal.

.. versionadded:: 22.1
.. versionchanged:: NEXT.VERSION
:attr:`gifts_from_channels` is now considered for equality checks.

Args:
unlimited_gifts (:class:`bool`): :obj:`True`, if unlimited regular gifts are accepted.
Expand All @@ -330,6 +332,10 @@ class AcceptedGiftTypes(TelegramObject):
to unique for free are accepted.
premium_subscription (:class:`bool`): :obj:`True`, if a Telegram Premium subscription
is accepted.
gifts_from_channels (:obj:`bool`): :obj:`True`, if transfers of unique gifts from channels
are accepted

.. versionadded:: NEXT.VERSION

Attributes:
unlimited_gifts (:class:`bool`): :obj:`True`, if unlimited regular gifts are accepted.
Expand All @@ -338,10 +344,15 @@ class AcceptedGiftTypes(TelegramObject):
to unique for free are accepted.
premium_subscription (:class:`bool`): :obj:`True`, if a Telegram Premium subscription
is accepted.
gifts_from_channels (:obj:`bool`): :obj:`True`, if transfers of unique gifts from channels
are accepted

.. versionadded:: NEXT.VERSION

"""

__slots__ = (
"gifts_from_channels",
"limited_gifts",
"premium_subscription",
"unique_gifts",
Expand All @@ -354,6 +365,7 @@ def __init__(
limited_gifts: bool,
unique_gifts: bool,
premium_subscription: bool,
gifts_from_channels: bool,
*,
api_kwargs: JSONDict | None = None,
):
Expand All @@ -362,12 +374,14 @@ def __init__(
self.limited_gifts: bool = limited_gifts
self.unique_gifts: bool = unique_gifts
self.premium_subscription: bool = premium_subscription
self.gifts_from_channels: bool = gifts_from_channels

self._id_attrs = (
self.unlimited_gifts,
self.limited_gifts,
self.unique_gifts,
self.premium_subscription,
self.gifts_from_channels,
)

self._freeze()
12 changes: 12 additions & 0 deletions src/telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ class Message(MaybeInaccessibleMessage):
was sent or received

.. versionadded:: 22.1
gift_upgrade_sent (:class:`telegram.GiftInfo`, optional): Service message: upgrade of a
gift was purchased after the gift was sent

.. versionadded:: NEXT.VERSION
giveaway_created (:class:`telegram.GiveawayCreated`, optional): Service message: a
scheduled giveaway was created

Expand Down Expand Up @@ -957,6 +961,10 @@ class Message(MaybeInaccessibleMessage):
was sent or received

.. versionadded:: 22.1
gift_upgrade_sent (:class:`telegram.GiftInfo`): Optional. Service message: upgrade of a
gift was purchased after the gift was sent

.. versionadded:: NEXT.VERSION
giveaway_created (:class:`telegram.GiveawayCreated`): Optional. Service message: a
scheduled giveaway was created

Expand Down Expand Up @@ -1125,6 +1133,7 @@ class Message(MaybeInaccessibleMessage):
"general_forum_topic_hidden",
"general_forum_topic_unhidden",
"gift",
"gift_upgrade_sent",
"giveaway",
"giveaway_completed",
"giveaway_created",
Expand Down Expand Up @@ -1296,6 +1305,7 @@ def __init__(
suggested_post_info: "SuggestedPostInfo | None" = None,
suggested_post_approved: "SuggestedPostApproved | None" = None,
suggested_post_approval_failed: "SuggestedPostApprovalFailed | None" = None,
gift_upgrade_sent: GiftInfo | None = None,
*,
api_kwargs: JSONDict | None = None,
):
Expand Down Expand Up @@ -1422,6 +1432,7 @@ def __init__(
self.suggested_post_approval_failed: SuggestedPostApprovalFailed | None = (
suggested_post_approval_failed
)
self.gift_upgrade_sent: GiftInfo | None = gift_upgrade_sent

self._effective_attachment = DEFAULT_NONE

Expand Down Expand Up @@ -1637,6 +1648,7 @@ def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Message":
data["suggested_post_approval_failed"] = de_json_optional(
data.get("suggested_post_approval_failed"), SuggestedPostApprovalFailed, bot
)
data["gift_upgrade_sent"] = de_json_optional(data.get("gift_upgrade_sent"), GiftInfo, bot)

api_kwargs = {}
# This is a deprecated field that TG still returns for backwards compatibility
Expand Down
5 changes: 5 additions & 0 deletions src/telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,11 @@ class MessageType(StringEnum):

.. versionadded:: 22.1
"""
GIFT_UPGRADE_SENT = "gift_upgrade_sent"
""":obj:`str`: Messages with :attr:`telegram.Message.gift_upgrade_sent`.

.. versionadded:: NEXT.VERSION
"""
GIVEAWAY = "giveaway"
""":obj:`str`: Messages with :attr:`telegram.Message.giveaway`.

Expand Down
13 changes: 13 additions & 0 deletions src/telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,7 @@ def filter(self, update: Update) -> bool:
or StatusUpdate.GENERAL_FORUM_TOPIC_HIDDEN.check_update(update)
or StatusUpdate.GENERAL_FORUM_TOPIC_UNHIDDEN.check_update(update)
or StatusUpdate.GIFT.check_update(update)
or StatusUpdate.GIFT_UPGRADE_SENT.check_update(update)
or StatusUpdate.GIVEAWAY_COMPLETED.check_update(update)
or StatusUpdate.GIVEAWAY_CREATED.check_update(update)
or StatusUpdate.LEFT_CHAT_MEMBER.check_update(update)
Expand Down Expand Up @@ -2188,6 +2189,18 @@ def filter(self, message: Message) -> bool:
.. versionadded:: 22.1
"""

class _GiftUpgradeSent(MessageFilter):
__slots__ = ()

def filter(self, message: Message) -> bool:
return bool(message.gift_upgrade_sent)

GIFT_UPGRADE_SENT = _GiftUpgradeSent(name="filters.StatusUpdate.GIFT_UPGRADE_SENT")
"""Messages that contain :attr:`telegram.Message.gift_upgrade_sent`.

.. versionadded:: NEXT.VERSION
"""

class _GiveawayCreated(MessageFilter):
__slots__ = ()

Expand Down
6 changes: 5 additions & 1 deletion tests/auxil/dummy_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@
accent_color_id=1,
max_reaction_count=1,
accepted_gift_types=AcceptedGiftTypes(
unlimited_gifts=True, limited_gifts=True, unique_gifts=True, premium_subscription=True
unlimited_gifts=True,
limited_gifts=True,
unique_gifts=True,
premium_subscription=True,
gifts_from_channels=True,
),
),
"ChatInviteLink": ChatInviteLink(
Expand Down
5 changes: 5 additions & 0 deletions tests/ext/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,11 @@ def test_filters_status_update(self, update):
assert filters.StatusUpdate.UNIQUE_GIFT.check_update(update)
update.message.unique_gift = None

update.message.gift_upgrade_sent = "gift_upgrade_sent"
assert filters.StatusUpdate.ALL.check_update(update)
assert filters.StatusUpdate.GIFT_UPGRADE_SENT.check_update(update)
update.message.gift_upgrade_sent = None

update.message.paid_message_price_changed = "paid_message_price_changed"
assert filters.StatusUpdate.ALL.check_update(update)
assert filters.StatusUpdate.PAID_MESSAGE_PRICE_CHANGED.check_update(update)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_business_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def make_assertion(*args, **kwargs):

async def test_set_business_account_gift_settings(self, offline_bot, monkeypatch):
show_gift_button = True
accepted_gift_types = AcceptedGiftTypes(True, True, True, True)
accepted_gift_types = AcceptedGiftTypes(True, True, True, True, True)

async def make_assertion(*args, **kwargs):
data = kwargs.get("request_data").json_parameters
Expand Down
2 changes: 1 addition & 1 deletion tests/test_chatfullinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ChatFullInfoTestBase:
first_name = "first_name"
last_name = "last_name"
can_send_paid_media = True
accepted_gift_types = AcceptedGiftTypes(True, True, True, True)
accepted_gift_types = AcceptedGiftTypes(True, True, True, True, True)
is_direct_messages = True
parent_chat = Chat(4, "channel", "channel")

Expand Down
12 changes: 11 additions & 1 deletion tests/test_gifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ def accepted_gift_types():
limited_gifts=AcceptedGiftTypesTestBase.limited_gifts,
unique_gifts=AcceptedGiftTypesTestBase.unique_gifts,
premium_subscription=AcceptedGiftTypesTestBase.premium_subscription,
gifts_from_channels=AcceptedGiftTypesTestBase.gifts_from_channels,
)


Expand All @@ -438,6 +439,7 @@ class AcceptedGiftTypesTestBase:
limited_gifts = True
unique_gifts = True
premium_subscription = True
gifts_from_channels = False


class TestAcceptedGiftTypesWithoutRequest(AcceptedGiftTypesTestBase):
Expand All @@ -454,31 +456,39 @@ def test_de_json(self, offline_bot):
"limited_gifts": self.limited_gifts,
"unique_gifts": self.unique_gifts,
"premium_subscription": self.premium_subscription,
"gifts_from_channels": self.gifts_from_channels,
}
accepted_gift_types = AcceptedGiftTypes.de_json(json_dict, offline_bot)
assert accepted_gift_types.api_kwargs == {}
assert accepted_gift_types.unlimited_gifts == self.unlimited_gifts
assert accepted_gift_types.limited_gifts == self.limited_gifts
assert accepted_gift_types.unique_gifts == self.unique_gifts
assert accepted_gift_types.premium_subscription == self.premium_subscription
assert accepted_gift_types.gifts_from_channels == self.gifts_from_channels

def test_to_dict(self, accepted_gift_types):
json_dict = accepted_gift_types.to_dict()
assert json_dict["unlimited_gifts"] == self.unlimited_gifts
assert json_dict["limited_gifts"] == self.limited_gifts
assert json_dict["unique_gifts"] == self.unique_gifts
assert json_dict["premium_subscription"] == self.premium_subscription
assert json_dict["gifts_from_channels"] == self.gifts_from_channels

def test_equality(self, accepted_gift_types):
a = accepted_gift_types
b = AcceptedGiftTypes(
self.unlimited_gifts, self.limited_gifts, self.unique_gifts, self.premium_subscription
self.unlimited_gifts,
self.limited_gifts,
self.unique_gifts,
self.premium_subscription,
self.gifts_from_channels,
)
c = AcceptedGiftTypes(
not self.unlimited_gifts,
self.limited_gifts,
self.unique_gifts,
self.premium_subscription,
self.gifts_from_channels,
)
d = BotCommand("start", "description")

Expand Down
10 changes: 10 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ def message(bot):
send_date=dtm.datetime.utcnow(),
)
},
{
"gift_upgrade_sent": GiftInfo(
gift=Gift(
"gift_id",
Sticker("file_id", "file_unique_id", 512, 512, False, False, "regular"),
5,
)
)
},
],
ids=[
"reply",
Expand Down Expand Up @@ -510,6 +519,7 @@ def message(bot):
"suggested_post_approved",
"suggested_post_approval_failed",
"suggested_post_info",
"gift_upgrade_sent",
],
)
def message_params(bot, request):
Expand Down
Loading