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 @@ -6,6 +6,7 @@ pull_requests = [
{ uid = "5079", author_uid = "aelkheir" },
{ uid = "5084", author_uids = ["Bibo-Joshi"] },
{ uid = "5085", author_uids = ["Bibo-Joshi"] },
{ uid = "5091", author_uids = ["Bibo-Joshi"] },
{ uid = "5090", author_uids = ["Bibo-Joshi"] },
{ uid = "5089", author_uids = ["Bibo-Joshi"] },
]
22 changes: 22 additions & 0 deletions src/telegram/_gifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ class GiftInfo(TelegramObject):
appear in the text.
is_private (:obj:`bool`, optional): :obj:`True`, if the sender and gift text are
shown only to the gift receiver; otherwise, everyone will be able to see them.
is_upgrade_separate (:obj:`bool`, optional): :obj:`True`, if the gift's upgrade was
purchased after the gift was sent.

.. versionadded:: NEXT.VERSION
unique_gift_number (:obj:`int`, optional): Unique number reserved for this gift when
upgraded. See the number field in :class:`~telegram.UniqueGift`.

.. versionadded:: NEXT.VERSION

Attributes:
gift (:class:`Gift`): Information about the gift.
Expand All @@ -320,6 +328,14 @@ class GiftInfo(TelegramObject):
appear in the text.
is_private (:obj:`bool`): Optional. :obj:`True`, if the sender and gift text are
shown only to the gift receiver; otherwise, everyone will be able to see them.
is_upgrade_separate (:obj:`bool`): Optional. :obj:`True`, if the gift's upgrade was
purchased after the gift was sent.

.. versionadded:: NEXT.VERSION
unique_gift_number (:obj:`int`): Optional. Unique number reserved for this gift when
upgraded. See the number field in :class:`~telegram.UniqueGift`.

.. versionadded:: NEXT.VERSION

"""

Expand All @@ -329,9 +345,11 @@ class GiftInfo(TelegramObject):
"entities",
"gift",
"is_private",
"is_upgrade_separate",
"owned_gift_id",
"prepaid_upgrade_star_count",
"text",
"unique_gift_number",
)

def __init__(
Expand All @@ -344,6 +362,8 @@ def __init__(
text: str | None = None,
entities: Sequence[MessageEntity] | None = None,
is_private: bool | None = None,
unique_gift_number: int | None = None,
is_upgrade_separate: bool | None = None,
*,
api_kwargs: JSONDict | None = None,
):
Expand All @@ -358,6 +378,8 @@ def __init__(
self.text: str | None = text
self.entities: tuple[MessageEntity, ...] = parse_sequence_arg(entities)
self.is_private: bool | None = is_private
self.unique_gift_number: int | None = unique_gift_number
self.is_upgrade_separate: bool | None = is_upgrade_separate

self._id_attrs = (self.gift,)

Expand Down
22 changes: 22 additions & 0 deletions src/telegram/_ownedgift.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class OwnedGiftRegular(OwnedGift):
to Telegram Stars.
prepaid_upgrade_star_count (:obj:`int`, optional): Number of Telegram Stars that were
paid by the sender for the ability to upgrade the gift.
is_upgrade_separate (:obj:`bool`, optional): :obj:`True`, if the gift's upgrade was
purchased after the gift was sent; for gifts received on behalf of business accounts

.. versionadded:: NEXT.VERSION
unique_gift_number (:obj:`int`, optional): Unique number reserved for this gift when
upgraded. See the number field in :class:`~telegram.UniqueGift`

... versionadded:: NEXT.VERSION

Attributes:
type (:obj:`str`): Type of the gift, always :attr:`~telegram.OwnedGift.REGULAR`.
Expand All @@ -211,6 +219,14 @@ class OwnedGiftRegular(OwnedGift):
to Telegram Stars.
prepaid_upgrade_star_count (:obj:`int`): Optional. Number of Telegram Stars that were
paid by the sender for the ability to upgrade the gift.
is_upgrade_separate (:obj:`bool`): Optional. :obj:`True`, if the gift's upgrade was
purchased after the gift was sent; for gifts received on behalf of business accounts

.. versionadded:: NEXT.VERSION
unique_gift_number (:obj:`int`): Optional. Unique number reserved for this gift when
upgraded. See the number field in :class:`~telegram.UniqueGift`

... versionadded:: NEXT.VERSION

"""

Expand All @@ -221,11 +237,13 @@ class OwnedGiftRegular(OwnedGift):
"gift",
"is_private",
"is_saved",
"is_upgrade_separate",
"owned_gift_id",
"prepaid_upgrade_star_count",
"send_date",
"sender_user",
"text",
"unique_gift_number",
"was_refunded",
)

Expand All @@ -243,6 +261,8 @@ def __init__(
was_refunded: bool | None = None,
convert_star_count: int | None = None,
prepaid_upgrade_star_count: int | None = None,
is_upgrade_separate: bool | None = None,
unique_gift_number: int | None = None,
*,
api_kwargs: JSONDict | None = None,
) -> None:
Expand All @@ -261,6 +281,8 @@ def __init__(
self.was_refunded: bool | None = was_refunded
self.convert_star_count: int | None = convert_star_count
self.prepaid_upgrade_star_count: int | None = prepaid_upgrade_star_count
self.is_upgrade_separate: bool | None = is_upgrade_separate
self.unique_gift_number: int | None = unique_gift_number

self._id_attrs = (self.type, self.gift, self.send_date)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_gifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ def gift_info():
text=GiftInfoTestBase.text,
entities=GiftInfoTestBase.entities,
is_private=GiftInfoTestBase.is_private,
is_upgrade_separate=GiftInfoTestBase.is_upgrade_separate,
unique_gift_number=GiftInfoTestBase.unique_gift_number,
)


Expand All @@ -433,6 +435,8 @@ class GiftInfoTestBase:
MessageEntity(MessageEntity.ITALIC, 5, 8),
)
is_private = True
is_upgrade_separate = False
unique_gift_number = 42


class TestGiftInfoWithoutRequest(GiftInfoTestBase):
Expand All @@ -451,6 +455,8 @@ def test_de_json(self, offline_bot):
"text": self.text,
"entities": [e.to_dict() for e in self.entities],
"is_private": self.is_private,
"is_upgrade_separate": self.is_upgrade_separate,
"unique_gift_number": self.unique_gift_number,
}
gift_info = GiftInfo.de_json(json_dict, offline_bot)
assert gift_info.api_kwargs == {}
Expand All @@ -462,6 +468,8 @@ def test_de_json(self, offline_bot):
assert gift_info.text == self.text
assert gift_info.entities == self.entities
assert gift_info.is_private == self.is_private
assert gift_info.is_upgrade_separate == self.is_upgrade_separate
assert gift_info.unique_gift_number == self.unique_gift_number

def test_to_dict(self, gift_info):
json_dict = gift_info.to_dict()
Expand All @@ -473,6 +481,8 @@ def test_to_dict(self, gift_info):
assert json_dict["text"] == self.text
assert json_dict["entities"] == [e.to_dict() for e in self.entities]
assert json_dict["is_private"] == self.is_private
assert json_dict["is_upgrade_separate"] == self.is_upgrade_separate
assert json_dict["unique_gift_number"] == self.unique_gift_number

def test_parse_entity(self, gift_info):
entity = MessageEntity(MessageEntity.BOLD, 0, 4)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_ownedgift.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class OwnedGiftTestBase:
can_be_transferred = True
transfer_star_count = 300
next_transfer_date = dtm.datetime.now(tz=UTC).replace(microsecond=0)
is_upgrade_separate = False
unique_gift_number = 37


class TestOwnedGiftWithoutRequest(OwnedGiftTestBase):
Expand Down Expand Up @@ -183,6 +185,8 @@ def owned_gift_regular():
was_refunded=TestOwnedGiftRegularWithoutRequest.was_refunded,
convert_star_count=TestOwnedGiftRegularWithoutRequest.convert_star_count,
prepaid_upgrade_star_count=TestOwnedGiftRegularWithoutRequest.prepaid_upgrade_star_count,
is_upgrade_separate=TestOwnedGiftRegularWithoutRequest.is_upgrade_separate,
unique_gift_number=TestOwnedGiftRegularWithoutRequest.unique_gift_number,
)


Expand All @@ -209,6 +213,8 @@ def test_de_json(self, offline_bot):
"was_refunded": self.was_refunded,
"convert_star_count": self.convert_star_count,
"prepaid_upgrade_star_count": self.prepaid_upgrade_star_count,
"is_upgrade_separate": self.is_upgrade_separate,
"unique_gift_number": self.unique_gift_number,
}
ogr = OwnedGiftRegular.de_json(json_dict, offline_bot)
assert ogr.gift == self.gift
Expand All @@ -223,6 +229,8 @@ def test_de_json(self, offline_bot):
assert ogr.was_refunded == self.was_refunded
assert ogr.convert_star_count == self.convert_star_count
assert ogr.prepaid_upgrade_star_count == self.prepaid_upgrade_star_count
assert ogr.is_upgrade_separate == self.is_upgrade_separate
assert ogr.unique_gift_number == self.unique_gift_number
assert ogr.api_kwargs == {}

def test_to_dict(self, owned_gift_regular):
Expand All @@ -241,6 +249,8 @@ def test_to_dict(self, owned_gift_regular):
assert json_dict["was_refunded"] == self.was_refunded
assert json_dict["convert_star_count"] == self.convert_star_count
assert json_dict["prepaid_upgrade_star_count"] == self.prepaid_upgrade_star_count
assert json_dict["is_upgrade_separate"] == self.is_upgrade_separate
assert json_dict["unique_gift_number"] == self.unique_gift_number

def test_parse_entity(self, owned_gift_regular):
entity = MessageEntity(MessageEntity.BOLD, 0, 4)
Expand Down
Loading