Skip to content

Commit

Permalink
Rename UserGift to ReceivedGift
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Mar 8, 2025
1 parent c8cc9c8 commit 9af6ccf
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 67 deletions.
6 changes: 3 additions & 3 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def get_title_list(s: str) -> list:
get_payment_form
send_payment_form
get_available_gifts
get_user_gifts
get_received_gifts
sell_gift
send_gift
toggle_gift_is_saved
Expand Down Expand Up @@ -522,7 +522,7 @@ def get_title_list(s: str) -> list:
Location
Venue
Gift
UserGift
ReceivedGift
UpgradedGift
WebAppData
MessageAutoDeleteTimerChanged
Expand Down Expand Up @@ -759,7 +759,7 @@ def get_title_list(s: str) -> list:
Message.translate
Message.pay
Message.star
UserGift.toggle
ReceivedGift.toggle
ExternalReplyInfo.download
""",
chat="""
Expand Down
1 change: 1 addition & 0 deletions docs/source/releases/changes-in-this-fork.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Changes in this Fork
| Scheme layer used: 200 |
+------------------------+

- Rename ``UserGift`` to :obj:`~pyrogram.types.ReceivedGift`, ``get_user_gifts`` to :meth:`~pyrogram.Client.get_received_gifts` and the corresponding fields appropriately.
- Added the field ``paid_message_star_count`` to the classes :obj:`~pyrogram.types.Chat`, :obj:`~pyrogram.types.Message` and :obj:`~pyrogram.types.User`.
- 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`.
- 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>`__.
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/enums/message_service_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class MessageServiceType(AutoName):
WRITE_ACCESS_ALLOWED = auto()
"The user accepted webapp bot's request to send messages"

USER_GIFT = auto()
"Star gift"
RECEIVED_GIFT = auto()
"Owner Received gift"

UNKNOWN = auto()
"This service message is unsupported by the current version of Pyrogram"
10 changes: 5 additions & 5 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ async def gift_code_filter(_, __, m: Message):

# endregion

# region user_gift
async def user_gift_filter(_, __, m: Message):
return bool(m.user_gift)
# region received_gift
async def received_gift_filter(_, __, m: Message):
return bool(m.received_gift)


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


# endregion
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/methods/business/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .send_payment_form import SendPaymentForm
from .get_available_gifts import GetAvailableGifts
from .get_owned_star_count import GetOwnedStarCount
from .get_user_gifts import GetUserGifts
from .get_received_gifts import GetReceivedGifts
from .sell_gift import SellGift
from .send_gift import SendGift
from .toggle_gift_is_saved import ToggleGiftIsSaved
Expand All @@ -45,7 +45,7 @@ class TelegramBusiness(
SendPaymentForm,
GetAvailableGifts,
GetOwnedStarCount,
GetUserGifts,
GetReceivedGifts,
SellGift,
SendGift,
ToggleGiftIsSaved,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@
from pyrogram import raw, types


class GetUserGifts:
async def get_user_gifts(
class GetReceivedGifts:
async def get_received_gifts(
self: "pyrogram.Client",
chat_id: Union[int, str],
owner_id: Union[int, str],
offset: str = "",
limit: int = 0,
) -> Optional[AsyncGenerator["types.UserGift", None]]:
"""Get gifts saved to profile by the given user.
exclude_unsaved: bool = None,
exclude_saved: bool = None,
exclude_unlimited: bool = None,
exclude_limited: bool = None,
exclude_upgraded: bool = None,
sort_by_price: bool = None
) -> Optional[AsyncGenerator["types.ReceivedGift", None]]:
"""Returns gifts received by the given user or chat.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
owner_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
Expand All @@ -46,16 +52,34 @@ async def get_user_gifts(
limit (``int``, *optional*):
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.
exclude_unsaved (``bool``, *optional*):
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.
exclude_saved (``bool``, *optional*):
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.
exclude_unlimited (``bool``, *optional*):
Pass True to exclude gifts that can be purchased unlimited number of times.
exclude_limited (``bool``, *optional*):
Pass True to exclude gifts that can be purchased limited number of times.
exclude_upgraded (``bool``, *optional*):
Pass True to exclude upgraded gifts.
sort_by_price (``bool``, *optional*):
Pass True to sort results by gift price instead of send date.
Returns:
``Generator``: A generator yielding :obj:`~pyrogram.types.UserGift` objects.
``Generator``: A generator yielding :obj:`~pyrogram.types.ReceivedGift` objects.
Example:
.. code-block:: python
async for user_gift in app.get_user_gifts(user_id):
print(user_gift)
async for received_gift in app.get_received_gifts(owner_id):
print(received_gift)
"""
peer = await self.resolve_peer(chat_id)
peer = await self.resolve_peer(owner_id)

current = 0
total = abs(limit) or (1 << 31) - 1
Expand All @@ -64,28 +88,33 @@ async def get_user_gifts(
while True:
r = await self.invoke(
raw.functions.payments.GetSavedStarGifts(
# TODO
peer=peer,
offset=offset,
limit=limit
limit=limit,
exclude_unsaved=exclude_unsaved,
exclude_saved=exclude_saved,
exclude_unlimited=exclude_unlimited,
exclude_limited=exclude_limited,
exclude_unique=exclude_upgraded,
sort_by_value=sort_by_price
),
sleep_threshold=60
)

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

user_gifts = [
await types.UserGift._parse(self, gift, users, chats)
received_gifts = [
await types.ReceivedGift._parse(self, gift, users, chats)
for gift in r.gifts
]

if not user_gifts:
if not received_gifts:
return

for user_gift in user_gifts:
for received_gift in received_gifts:
await sleep(0)
yield user_gift
yield received_gift

current += 1

Expand Down
4 changes: 2 additions & 2 deletions pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from .sponsored_message import SponsoredMessage
from .gift import Gift
from .user_gift import UserGift
from .received_gift import ReceivedGift
from .upgraded_gift import UpgradedGift
from .sticker import Sticker
from .stripped_thumbnail import StrippedThumbnail
Expand Down Expand Up @@ -111,7 +111,7 @@
"PollOption",
"SponsoredMessage",
"Gift",
"UserGift",
"ReceivedGift",
"UpgradedGift",
"Sticker",
"Story",
Expand Down
14 changes: 7 additions & 7 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class Message(Object, Update):
gifted_stars (:obj:`~pyrogram.types.GiftedStars`, *optional*):
Info about gifted Telegram Stars
user_gift (:obj:`~pyrogram.types.UserGift`, *optional*):
received_gift (:obj:`~pyrogram.types.ReceivedGift`, *optional*):
Service message: Represents a gift received by a user.
contact_registered (:obj:`~pyrogram.types.ContactRegistered`, *optional*):
Expand Down Expand Up @@ -531,7 +531,7 @@ def __init__(
gift_code: "types.GiftCode" = None,
gifted_premium: "types.GiftedPremium" = None,
gifted_stars: "types.GiftedStars" = None,
user_gift: "types.UserGift" = None,
received_gift: "types.ReceivedGift" = None,
empty: bool = None,
mentioned: bool = None,
service: "enums.MessageServiceType" = None,
Expand Down Expand Up @@ -654,7 +654,7 @@ def __init__(
self.custom_action = custom_action
self.sender_business_bot = sender_business_bot
self.business_connection_id = business_connection_id
self.user_gift = user_gift
self.received_gift = received_gift
self.successful_payment = successful_payment
self.paid_media = paid_media
self.refunded_payment = refunded_payment
Expand Down Expand Up @@ -765,7 +765,7 @@ async def _parse(
chat_join_type = None
screenshot_taken = None

user_gift = None
received_gift = None

service_type = enums.MessageServiceType.UNKNOWN

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

parsed_message = Message(
id=message.id,
Expand Down Expand Up @@ -1058,7 +1058,7 @@ async def _parse(
chat_shared=chat_shared,
connected_website=connected_website,
write_access_allowed=write_access_allowed,
user_gift=user_gift,
received_gift=received_gift,
successful_payment=successful_payment,
message_auto_delete_timer_changed=message_auto_delete_timer_changed,
boost_added=boost_added,
Expand Down
Loading

0 comments on commit 9af6ccf

Please sign in to comment.