Skip to content

Commit 9af6ccf

Browse files
committed
Rename UserGift to ReceivedGift
1 parent c8cc9c8 commit 9af6ccf

File tree

9 files changed

+103
-67
lines changed

9 files changed

+103
-67
lines changed

compiler/docs/compiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def get_title_list(s: str) -> list:
402402
get_payment_form
403403
send_payment_form
404404
get_available_gifts
405-
get_user_gifts
405+
get_received_gifts
406406
sell_gift
407407
send_gift
408408
toggle_gift_is_saved
@@ -522,7 +522,7 @@ def get_title_list(s: str) -> list:
522522
Location
523523
Venue
524524
Gift
525-
UserGift
525+
ReceivedGift
526526
UpgradedGift
527527
WebAppData
528528
MessageAutoDeleteTimerChanged
@@ -759,7 +759,7 @@ def get_title_list(s: str) -> list:
759759
Message.translate
760760
Message.pay
761761
Message.star
762-
UserGift.toggle
762+
ReceivedGift.toggle
763763
ExternalReplyInfo.download
764764
""",
765765
chat="""

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Changes in this Fork
3333
| Scheme layer used: 200 |
3434
+------------------------+
3535

36+
- Rename ``UserGift`` to :obj:`~pyrogram.types.ReceivedGift`, ``get_user_gifts`` to :meth:`~pyrogram.Client.get_received_gifts` and the corresponding fields appropriately.
3637
- Added the field ``paid_message_star_count`` to the classes :obj:`~pyrogram.types.Chat`, :obj:`~pyrogram.types.Message` and :obj:`~pyrogram.types.User`.
3738
- Added the parameter ``paid_message_star_count`` to the methods :meth:`~pyrogram.Client.copy_media_group`, :meth:`~pyrogram.Client.send_game`, :meth:`~pyrogram.Client.send_invoice`, :meth:`~pyrogram.Client.forward_messages`, :meth:`~pyrogram.Client.send_animation`, :meth:`~pyrogram.Client.send_audio`, :meth:`~pyrogram.Client.send_cached_media`, :meth:`~pyrogram.Client.send_contact`, :meth:`~pyrogram.Client.send_dice`, :meth:`~pyrogram.Client.send_document`, :meth:`~pyrogram.Client.send_location`, :meth:`~pyrogram.Client.send_media_group`, :meth:`~pyrogram.Client.send_message`, :meth:`~pyrogram.Client.send_paid_media`, :meth:`~pyrogram.Client.send_photo`, :meth:`~pyrogram.Client.send_poll`, :meth:`~pyrogram.Client.send_sticker`, :meth:`~pyrogram.Client.send_venue`, :meth:`~pyrogram.Client.send_video_note`, :meth:`~pyrogram.Client.send_video`, :meth:`~pyrogram.Client.send_voice` and the bound methods :meth:`~pyrogram.types.Message.forward` and :meth:`~pyrogram.types.Message.copy`.
3839
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=199&to=200>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=199&to=200>`__.

pyrogram/enums/message_service_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class MessageServiceType(AutoName):
141141
WRITE_ACCESS_ALLOWED = auto()
142142
"The user accepted webapp bot's request to send messages"
143143

144-
USER_GIFT = auto()
145-
"Star gift"
144+
RECEIVED_GIFT = auto()
145+
"Owner Received gift"
146146

147147
UNKNOWN = auto()
148148
"This service message is unsupported by the current version of Pyrogram"

pyrogram/filters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ async def gift_code_filter(_, __, m: Message):
367367

368368
# endregion
369369

370-
# region user_gift
371-
async def user_gift_filter(_, __, m: Message):
372-
return bool(m.user_gift)
370+
# region received_gift
371+
async def received_gift_filter(_, __, m: Message):
372+
return bool(m.received_gift)
373373

374374

375-
user_gift = create(user_gift_filter)
376-
"""Filter messages that contain :obj:`~pyrogram.types.UserGift` objects."""
375+
received_gift = create(received_gift_filter)
376+
"""Filter messages that contain :obj:`~pyrogram.types.ReceivedGift` objects."""
377377

378378

379379
# endregion

pyrogram/methods/business/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .send_payment_form import SendPaymentForm
2828
from .get_available_gifts import GetAvailableGifts
2929
from .get_owned_star_count import GetOwnedStarCount
30-
from .get_user_gifts import GetUserGifts
30+
from .get_received_gifts import GetReceivedGifts
3131
from .sell_gift import SellGift
3232
from .send_gift import SendGift
3333
from .toggle_gift_is_saved import ToggleGiftIsSaved
@@ -45,7 +45,7 @@ class TelegramBusiness(
4545
SendPaymentForm,
4646
GetAvailableGifts,
4747
GetOwnedStarCount,
48-
GetUserGifts,
48+
GetReceivedGifts,
4949
SellGift,
5050
SendGift,
5151
ToggleGiftIsSaved,

pyrogram/methods/business/get_user_gifts.py renamed to pyrogram/methods/business/get_received_gifts.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@
2323
from pyrogram import raw, types
2424

2525

26-
class GetUserGifts:
27-
async def get_user_gifts(
26+
class GetReceivedGifts:
27+
async def get_received_gifts(
2828
self: "pyrogram.Client",
29-
chat_id: Union[int, str],
29+
owner_id: Union[int, str],
3030
offset: str = "",
3131
limit: int = 0,
32-
) -> Optional[AsyncGenerator["types.UserGift", None]]:
33-
"""Get gifts saved to profile by the given user.
32+
exclude_unsaved: bool = None,
33+
exclude_saved: bool = None,
34+
exclude_unlimited: bool = None,
35+
exclude_limited: bool = None,
36+
exclude_upgraded: bool = None,
37+
sort_by_price: bool = None
38+
) -> Optional[AsyncGenerator["types.ReceivedGift", None]]:
39+
"""Returns gifts received by the given user or chat.
3440
3541
.. include:: /_includes/usable-by/users.rst
3642
3743
Parameters:
38-
chat_id (``int`` | ``str``):
44+
owner_id (``int`` | ``str``):
3945
Unique identifier (int) or username (str) of the target chat.
4046
For your personal cloud (Saved Messages) you can simply use "me" or "self".
4147
For a contact that exists in your Telegram address book you can use his phone number (str).
@@ -46,16 +52,34 @@ async def get_user_gifts(
4652
limit (``int``, *optional*):
4753
The maximum number of gifts to be returned; must be positive and can't be greater than 100. For optimal performance, the number of returned objects is chosen by Telegram Server and can be smaller than the specified limit.
4854
55+
exclude_unsaved (``bool``, *optional*):
56+
Pass True to exclude gifts that aren't saved to the chat's profile page. Always True for gifts received by other users and channel chats without ``can_post_messages`` administrator right.
57+
58+
exclude_saved (``bool``, *optional*):
59+
Pass True to exclude gifts that are saved to the chat's profile page. Always False for gifts received by other users and channel chats without ``can_post_messages`` administrator right.
60+
61+
exclude_unlimited (``bool``, *optional*):
62+
Pass True to exclude gifts that can be purchased unlimited number of times.
63+
64+
exclude_limited (``bool``, *optional*):
65+
Pass True to exclude gifts that can be purchased limited number of times.
66+
67+
exclude_upgraded (``bool``, *optional*):
68+
Pass True to exclude upgraded gifts.
69+
70+
sort_by_price (``bool``, *optional*):
71+
Pass True to sort results by gift price instead of send date.
72+
4973
Returns:
50-
``Generator``: A generator yielding :obj:`~pyrogram.types.UserGift` objects.
74+
``Generator``: A generator yielding :obj:`~pyrogram.types.ReceivedGift` objects.
5175
5276
Example:
5377
.. code-block:: python
5478
55-
async for user_gift in app.get_user_gifts(user_id):
56-
print(user_gift)
79+
async for received_gift in app.get_received_gifts(owner_id):
80+
print(received_gift)
5781
"""
58-
peer = await self.resolve_peer(chat_id)
82+
peer = await self.resolve_peer(owner_id)
5983

6084
current = 0
6185
total = abs(limit) or (1 << 31) - 1
@@ -64,28 +88,33 @@ async def get_user_gifts(
6488
while True:
6589
r = await self.invoke(
6690
raw.functions.payments.GetSavedStarGifts(
67-
# TODO
6891
peer=peer,
6992
offset=offset,
70-
limit=limit
93+
limit=limit,
94+
exclude_unsaved=exclude_unsaved,
95+
exclude_saved=exclude_saved,
96+
exclude_unlimited=exclude_unlimited,
97+
exclude_limited=exclude_limited,
98+
exclude_unique=exclude_upgraded,
99+
sort_by_value=sort_by_price
71100
),
72101
sleep_threshold=60
73102
)
74103

75104
users = {u.id: u for u in r.users}
76105
chats = {c.id: c for c in r.chats}
77106

78-
user_gifts = [
79-
await types.UserGift._parse(self, gift, users, chats)
107+
received_gifts = [
108+
await types.ReceivedGift._parse(self, gift, users, chats)
80109
for gift in r.gifts
81110
]
82111

83-
if not user_gifts:
112+
if not received_gifts:
84113
return
85114

86-
for user_gift in user_gifts:
115+
for received_gift in received_gifts:
87116
await sleep(0)
88-
yield user_gift
117+
yield received_gift
89118

90119
current += 1
91120

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242
from .sponsored_message import SponsoredMessage
4343
from .gift import Gift
44-
from .user_gift import UserGift
44+
from .received_gift import ReceivedGift
4545
from .upgraded_gift import UpgradedGift
4646
from .sticker import Sticker
4747
from .stripped_thumbnail import StrippedThumbnail
@@ -111,7 +111,7 @@
111111
"PollOption",
112112
"SponsoredMessage",
113113
"Gift",
114-
"UserGift",
114+
"ReceivedGift",
115115
"UpgradedGift",
116116
"Sticker",
117117
"Story",

pyrogram/types/messages_and_media/message.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class Message(Object, Update):
403403
gifted_stars (:obj:`~pyrogram.types.GiftedStars`, *optional*):
404404
Info about gifted Telegram Stars
405405
406-
user_gift (:obj:`~pyrogram.types.UserGift`, *optional*):
406+
received_gift (:obj:`~pyrogram.types.ReceivedGift`, *optional*):
407407
Service message: Represents a gift received by a user.
408408
409409
contact_registered (:obj:`~pyrogram.types.ContactRegistered`, *optional*):
@@ -531,7 +531,7 @@ def __init__(
531531
gift_code: "types.GiftCode" = None,
532532
gifted_premium: "types.GiftedPremium" = None,
533533
gifted_stars: "types.GiftedStars" = None,
534-
user_gift: "types.UserGift" = None,
534+
received_gift: "types.ReceivedGift" = None,
535535
empty: bool = None,
536536
mentioned: bool = None,
537537
service: "enums.MessageServiceType" = None,
@@ -654,7 +654,7 @@ def __init__(
654654
self.custom_action = custom_action
655655
self.sender_business_bot = sender_business_bot
656656
self.business_connection_id = business_connection_id
657-
self.user_gift = user_gift
657+
self.received_gift = received_gift
658658
self.successful_payment = successful_payment
659659
self.paid_media = paid_media
660660
self.refunded_payment = refunded_payment
@@ -765,7 +765,7 @@ async def _parse(
765765
chat_join_type = None
766766
screenshot_taken = None
767767

768-
user_gift = None
768+
received_gift = None
769769

770770
service_type = enums.MessageServiceType.UNKNOWN
771771

@@ -1024,8 +1024,8 @@ async def _parse(
10241024
isinstance(action, raw.types.MessageActionStarGift) or
10251025
isinstance(action, raw.types.MessageActionStarGiftUnique)
10261026
):
1027-
user_gift = await types.UserGift._parse_action(client, message, users, chats)
1028-
service_type = enums.MessageServiceType.USER_GIFT
1027+
received_gift = await types.ReceivedGift._parse_action(client, message, users, chats)
1028+
service_type = enums.MessageServiceType.RECEIVED_GIFT
10291029

10301030
parsed_message = Message(
10311031
id=message.id,
@@ -1058,7 +1058,7 @@ async def _parse(
10581058
chat_shared=chat_shared,
10591059
connected_website=connected_website,
10601060
write_access_allowed=write_access_allowed,
1061-
user_gift=user_gift,
1061+
received_gift=received_gift,
10621062
successful_payment=successful_payment,
10631063
message_auto_delete_timer_changed=message_auto_delete_timer_changed,
10641064
boost_added=boost_added,

0 commit comments

Comments
 (0)