Skip to content

Commit f4fb1f4

Browse files
committed
Add can_be_transferred, transfer_star_count, export_date to UserGift
1 parent a714e55 commit f4fb1f4

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

docs/source/releases/changes-in-this-fork.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Changes in this Fork
2626
+------------------------+
2727

2828
- Added the :meth:`~pyrogram.Client.on_bot_purchased_paid_media` and :meth:`~pyrogram.Client.on_bot_business_connection`.
29-
- Added the parameters ``can_be_upgraded``, ``was_refunded``, ``prepaid_upgrade_star_count`` in :obj:`~pyrogram.types.UserGift`.
29+
- Added the parameters ``can_be_upgraded``, ``was_refunded``, ``prepaid_upgrade_star_count``, ``can_be_transferred``, ``transfer_star_count``, ``export_date`` in :obj:`~pyrogram.types.UserGift`.
3030
- Renamed the parameter ``only_in_channels`` to ``chat_type_filter`` in the :meth:`~pyrogram.Client.search_global_count` and :meth:`~pyrogram.Client.search_global`.
3131
- Removed ``sender_user_id`` parameter from :meth:`~pyrogram.Client.sell_gift` and :meth:`~pyrogram.Client.toggle_gift_is_saved`.
3232
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=195&to=196>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=195&to=196>`__.

pyrogram/types/messages_and_media/message.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,10 @@ async def _parse(
10021002
write_access_allowed = types.WriteAccessAllowed._parse(action)
10031003
service_type = enums.MessageServiceType.WRITE_ACCESS_ALLOWED
10041004

1005-
elif isinstance(action, raw.types.MessageActionStarGift):
1005+
elif (
1006+
isinstance(action, raw.types.MessageActionStarGift) or
1007+
isinstance(action, raw.types.MessageActionStarGiftUnique)
1008+
):
10061009
user_gift = await types.UserGift._parse_action(client, message, users)
10071010
service_type = enums.MessageServiceType.USER_GIFT
10081011

pyrogram/types/messages_and_media/user_gift.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class UserGift(Object):
4444
is_saved (``bool``, *optional*):
4545
True, if the gift is displayed on the user's profile page; may be False only for the receiver of the gift.
4646
47-
date (``datetime``):
47+
date (:py:obj:`~datetime.datetime`, *optional*):
4848
Date when the gift was sent.
4949
5050
gift (:obj:`~pyrogram.types.Gift`, *optional*):
@@ -68,6 +68,15 @@ class UserGift(Object):
6868
prepaid_upgrade_star_count (``int``, *optional*):
6969
Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
7070
71+
can_be_transferred (``bool``, *optional*):
72+
True, if the gift is an upgraded gift that can be transferred to another user; only for the receiver of the gift.
73+
74+
transfer_star_count (``int``, *optional*):
75+
Number of Telegram Stars that must be paid to transfer the upgraded gift; only for the receiver of the gift.
76+
77+
export_date (:py:obj:`~datetime.datetime`, *optional*):
78+
Point in time (Unix timestamp) when the upgraded gift can be transferred to TON blockchain as an NFT; None if NFT export isn't possible; only for the receiver of the gift.
79+
7180
"""
7281

7382
def __init__(
@@ -87,6 +96,9 @@ def __init__(
8796
can_be_upgraded: Optional[bool] = None,
8897
was_refunded: Optional[bool] = None,
8998
prepaid_upgrade_star_count: Optional[int] = None,
99+
can_be_transferred: Optional[bool] = None,
100+
transfer_star_count: Optional[int] = None,
101+
export_date: datetime = None,
90102
):
91103
super().__init__(client)
92104

@@ -103,6 +115,10 @@ def __init__(
103115
self.can_be_upgraded = can_be_upgraded
104116
self.was_refunded = was_refunded
105117
self.prepaid_upgrade_star_count = prepaid_upgrade_star_count
118+
self.can_be_transferred = can_be_transferred
119+
self.transfer_star_count = transfer_star_count
120+
self.export_date = export_date
121+
106122

107123
@staticmethod
108124
async def _parse(
@@ -135,7 +151,7 @@ async def _parse_action(
135151
message: "raw.base.Message",
136152
users: dict
137153
) -> "UserGift":
138-
action = message.action # raw.types.MessageActionStarGift
154+
action = message.action
139155

140156
doc = action.gift.sticker
141157
attributes = {type(i): i for i in doc.attributes}
@@ -146,30 +162,55 @@ async def _parse_action(
146162
entities = [types.MessageEntity._parse(client, entity, users) for entity in action.message.entities]
147163
entities = types.List(filter(lambda x: x is not None, entities))
148164

149-
return UserGift(
150-
gift=types.Gift(
151-
id=action.gift.id,
152-
sticker=await types.Sticker._parse(client, doc, attributes),
153-
star_count=action.gift.stars,
154-
total_count=getattr(action.gift, "availability_total", None),
155-
remaining_count=getattr(action.gift, "availability_remains", None),
156-
default_sell_star_count=action.gift.convert_stars,
157-
is_limited=getattr(action.gift, "limited", None),
158-
),
159-
date=utils.timestamp_to_datetime(message.date),
160-
is_private=getattr(action, "name_hidden", None),
161-
is_saved=getattr(action, "saved", None),
162-
sender_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
163-
message_id=message.id,
164-
text=Str(text).init(entities) if text else None,
165-
entities=entities,
166-
sell_star_count=getattr(action, "convert_stars", None),
167-
was_converted=getattr(action, "converted", None),
168-
can_be_upgraded=getattr(action, "can_upgrade", None),
169-
was_refunded=getattr(action, "refunded", None),
170-
prepaid_upgrade_star_count=getattr(action, "upgrade_stars", None),
171-
client=client
172-
)
165+
if isinstance(action, raw.types.MessageActionStarGift):
166+
return UserGift(
167+
gift=types.Gift(
168+
id=action.gift.id,
169+
sticker=await types.Sticker._parse(client, doc, attributes),
170+
star_count=action.gift.stars,
171+
total_count=getattr(action.gift, "availability_total", None),
172+
remaining_count=getattr(action.gift, "availability_remains", None),
173+
default_sell_star_count=action.gift.convert_stars,
174+
is_limited=getattr(action.gift, "limited", None),
175+
),
176+
date=utils.timestamp_to_datetime(message.date),
177+
is_private=getattr(action, "name_hidden", None),
178+
is_saved=getattr(action, "saved", None),
179+
sender_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
180+
message_id=message.id,
181+
text=Str(text).init(entities) if text else None,
182+
entities=entities,
183+
sell_star_count=getattr(action, "convert_stars", None),
184+
was_converted=getattr(action, "converted", None),
185+
can_be_upgraded=getattr(action, "can_upgrade", None),
186+
was_refunded=getattr(action, "refunded", None),
187+
prepaid_upgrade_star_count=getattr(action, "upgrade_stars", None),
188+
client=client
189+
)
190+
191+
if isinstance(action, raw.types.MessageActionStarGiftUnique):
192+
return UserGift(
193+
gift=types.Gift(
194+
id=action.gift.id,
195+
sticker=await types.Sticker._parse(client, doc, attributes),
196+
star_count=action.gift.stars,
197+
total_count=getattr(action.gift, "availability_total", None),
198+
remaining_count=getattr(action.gift, "availability_remains", None),
199+
default_sell_star_count=action.gift.convert_stars,
200+
is_limited=getattr(action.gift, "limited", None),
201+
),
202+
date=utils.timestamp_to_datetime(message.date),
203+
sender_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
204+
message_id=message.id,
205+
text=Str(text).init(entities) if text else None,
206+
entities=entities,
207+
can_be_transferred=getattr(action, "transferred", None),
208+
was_refunded=getattr(action, "refunded", None),
209+
prepaid_upgrade_star_count=getattr(action, "upgrade_stars", None),
210+
export_date=utils.timestamp_to_datetime(action.can_export_at) if action.can_export_at else None,
211+
transfer_star_count=getattr(action, "transfer_stars", None),
212+
client=client
213+
)
173214

174215
async def toggle(self, is_saved: bool) -> bool:
175216
"""Bound method *toggle* of :obj:`~pyrogram.types.UserGift`.

0 commit comments

Comments
 (0)