Skip to content

Commit f29741e

Browse files
Update methods and types to layer 210
Closes #206
1 parent 4e9389b commit f29741e

13 files changed

Lines changed: 424 additions & 66 deletions

File tree

compiler/docs/compiler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ def get_title_list(s: str) -> list:
636636
FoundContacts
637637
PrivacyRule
638638
StoriesStealthMode
639+
UserRating
639640
BotVerification
640641
BusinessBotRights
641642
ChatSettings
@@ -709,6 +710,11 @@ def get_title_list(s: str) -> list:
709710
Invoice
710711
LinkPreviewOptions
711712
GiftCode
713+
GiftPurchaseLimit
714+
GiftResaleParameters
715+
GiftResalePrice
716+
GiftResalePriceStar
717+
GiftResalePriceTon
712718
GiftUpgradePreview
713719
CheckedGiftCode
714720
ChecklistTask

pyrogram/methods/payments/send_resold_gift.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def send_resold_gift(
2828
self: "pyrogram.Client",
2929
gift_link: str,
3030
new_owner_chat_id: Union[int, str],
31-
star_count: int = None
31+
price: "types.GiftResalePrice",
3232
) -> Optional["types.Message"]:
3333
"""Send an upgraded gift that is available for resale to another user or channel chat.
3434
@@ -47,17 +47,21 @@ async def send_resold_gift(
4747
For your personal cloud (Saved Messages) you can simply use "me" or "self".
4848
For a contact that exists in your Telegram address book you can use his phone number (str).
4949
50-
star_count (``int``, *optional*):
51-
The amount of Telegram Stars required to pay for the gift.
50+
price (:obj:`~pyrogram.types.GiftResalePrice`, *optional*):
51+
The price that the user agreed to pay for the gift.
5252
5353
Returns:
5454
:obj:`~pyrogram.types.Message`: On success, the sent message is returned.
5555
5656
Example:
5757
.. code-block:: python
5858
59-
# Transfer gift to another user
60-
await app.send_resold_gift(gift_link="https://t.me/nft/NekoHelmet-9215", new_owner_chat_id=123)
59+
# Buy gift from telegram market and transfer it to another user
60+
await app.send_resold_gift(
61+
gift_link="https://t.me/nft/NekoHelmet-9215",
62+
new_owner_chat_id=123,
63+
price=types.GiftResalePriceStar(star_count=100_000)
64+
)
6165
"""
6266
match = self.UPGRADED_GIFT_RE.match(gift_link)
6367

@@ -70,7 +74,8 @@ async def send_resold_gift(
7074

7175
invoice = raw.types.InputInvoiceStarGiftResale(
7276
slug=match.group(1),
73-
to_id=peer
77+
to_id=peer,
78+
ton=isinstance(price, types.GiftResalePriceTon)
7479
)
7580

7681
form = await self.invoke(
@@ -79,12 +84,18 @@ async def send_resold_gift(
7984
)
8085
)
8186

82-
if star_count is not None:
83-
if star_count < 0:
84-
raise ValueError("Invalid amount of Telegram Stars specified.")
87+
if isinstance(price, types.GiftResalePriceTon):
88+
amount = price.toncoin_cent_count
89+
else:
90+
amount = price.star_count
8591

86-
if form.invoice.prices[0].amount > star_count:
87-
raise ValueError("Have not enough Telegram Stars.")
92+
if amount < 0:
93+
raise ValueError("Invalid price specified.")
94+
95+
if form.invoice.prices[0].amount > amount:
96+
raise ValueError("Have not enough {}".format(
97+
"Toncoins" if isinstance(price, types.GiftResalePriceTon) else "Telegram Stars"
98+
))
8899

89100
r = await self.invoke(
90101
raw.functions.payments.SendStarsForm(

pyrogram/methods/payments/set_gift_resale_price.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import re
2020

2121
import pyrogram
22-
from pyrogram import raw
22+
from pyrogram import raw, types
2323

2424

2525
class SetGiftResalePrice:
2626
async def set_gift_resale_price(
2727
self: "pyrogram.Client",
2828
owned_gift_id: str,
29-
resale_star_count: int
29+
price: "types.GiftResalePrice" = None,
3030
) -> bool:
3131
"""Change resale price of a unique gift owned by the current user.
3232
@@ -39,8 +39,9 @@ async def set_gift_resale_price(
3939
For a channel gift, you can use the packed format `chatID_savedID` (str).
4040
For a upgraded gift, you can use the gift link.
4141
42-
resale_star_count (``int``):
43-
The new price for the unique gift. Pass 0 to disallow gift resale.
42+
price (:obj:`~pyrogram.types.GiftResalePrice`, *optional*):
43+
The new price for the unique gift.
44+
Pass None to disallow gift resale.
4445
4546
Returns:
4647
``bool``: On success, True is returned.
@@ -49,7 +50,19 @@ async def set_gift_resale_price(
4950
.. code-block:: python
5051
5152
# Change resale price of a unique gift
52-
await app.set_gift_resale_price(owned_gift_id="123456", resale_star_count=100)
53+
await app.set_gift_resale_price(
54+
owned_gift_id="123456",
55+
price=types.GiftResalePriceStar(star_count=100)
56+
)
57+
58+
# Change resale price of a unique gift to 10 TONs
59+
await app.set_gift_resale_price(
60+
owned_gift_id="123456",
61+
price=types.GiftResalePriceTon(toncoin_cent_count=10000000000) # You can use utils.to_nano(10) for same result
62+
)
63+
64+
# Disallow resale of a unique gift
65+
await app.set_gift_resale_price(owned_gift_id="123456")
5366
"""
5467
if not isinstance(owned_gift_id, str):
5568
raise ValueError(f"owned_gift_id has to be str, but {type(owned_gift_id)} was provided")
@@ -74,7 +87,7 @@ async def set_gift_resale_price(
7487
await self.invoke(
7588
raw.functions.payments.UpdateStarGiftPrice(
7689
stargift=stargift,
77-
resell_amount=raw.types.StarsAmount(amount=resale_star_count, nanos=0)
90+
resell_amount=raw.types.StarsAmount(amount=0, nanos=0) if price is None else price.write()
7891
)
7992
)
8093

pyrogram/types/messages_and_media/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
from .general_forum_topic_hidden import GeneralForumTopicHidden
4848
from .general_forum_topic_unhidden import GeneralForumTopicUnhidden
4949
from .gift_code import GiftCode
50+
from .gift_purchase_limit import GiftPurchaseLimit
51+
from .gift_resale_parameters import GiftResaleParameters
52+
from .gift_resale_price import GiftResalePrice, GiftResalePriceStar, GiftResalePriceTon
5053
from .gift_upgrade_preview import GiftUpgradePreview
5154
from .invoice import Invoice
5255
from .link_preview_options import LinkPreviewOptions
@@ -152,6 +155,11 @@
152155
"GeneralForumTopicHidden",
153156
"GeneralForumTopicUnhidden",
154157
"GiftCode",
158+
"GiftPurchaseLimit",
159+
"GiftResaleParameters",
160+
"GiftResalePrice",
161+
"GiftResalePriceStar",
162+
"GiftResalePriceTon",
155163
"GiftUpgradePreview",
156164
"Giveaway",
157165
"InputChecklistTask",

pyrogram/types/messages_and_media/gift.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,31 @@ class Gift(Object):
9898
transfer_price (``int``, *optional*):
9999
The number of stars you need to transfer this gift.
100100
101-
resale_price (``int``, *optional*):
102-
Number of Telegram Stars that must be paid to buy the gift and send it to someone else.
103-
104-
last_resale_star_count (``int``, *optional*):
105-
Number of Telegram Stars that were paid by the sender for the gift.
106-
107-
last_resale_ton_count (``int``, *optional*):
108-
Number of TON that were paid by the sender for the gift.
109-
110101
number (``int``, *optional*):
111102
Unique number of the upgraded gift among gifts upgraded from the same gift.
112103
104+
total_upgraded_count (``int``, *optional*):
105+
Total number of gifts that were upgraded from the same gift.
106+
107+
max_upgraded_count (``int``, *optional*):
108+
The maximum number of gifts that can be upgraded from the same gift.
109+
113110
available_resale_amount (``int``, *optional*):
114111
The number of gifts available for resale.
115112
Returned only if is_limited is True.
116113
117-
available_amount (``int``, *optional*):
118-
The number of gifts available for purchase.
119-
Returned only if is_limited is True.
114+
user_limits (:obj:`~pyrogram.types.GiftPurchaseLimit`, *optional*):
115+
Number of times the gift can be purchased by the current user.
120116
121-
total_amount (``int``, *optional*):
122-
Total amount of gifts.
123-
Returned only if is_limited is True.
117+
overall_limits (:obj:`~pyrogram.types.GiftPurchaseLimit`, *optional*):
118+
Number of times the gift can be purchased all users.
124119
125120
publisher_chat (:obj:`~pyrogram.types.Chat`, *optional*):
126121
Information about the chat that published the gift.
127122
123+
resale_parameters (:obj:`~pyrogram.types.GiftResaleParameters`, *optional*):
124+
Resale parameters of the gift.
125+
128126
can_upgrade (``bool``, *optional*):
129127
True, if the gift can be upgraded.
130128
@@ -162,9 +160,12 @@ class Gift(Object):
162160
is_transferred (``bool``, *optional*):
163161
True, if the gift was transferred.
164162
165-
is_birthday (``bool``, *optional*):
163+
is_for_birthday (``bool``, *optional*):
166164
True, if the gift is a birthday gift.
167165
166+
is_premium (``bool``, *optional*):
167+
True, if the gift can be bought only by Telegram Premium users.
168+
168169
is_pinned (``bool``, *optional*):
169170
True, if the gift is pinned.
170171
@@ -197,19 +198,19 @@ def __init__(
197198
convert_price: Optional[int] = None,
198199
upgrade_price: Optional[int] = None,
199200
transfer_price: Optional[int] = None,
200-
resale_price: Optional[int] = None,
201-
last_resale_star_count: Optional[int] = None,
202-
last_resale_ton_count: Optional[int] = None,
203201
upgrade_message_id: Optional[int] = None,
204202
name: Optional[str] = None,
205203
title: Optional[str] = None,
206204
collectible_id: Optional[int] = None,
207205
attributes: Optional[List["types.GiftAttribute"]] = None,
208206
number: Optional[int] = None,
207+
total_upgraded_count: Optional[int] = None,
208+
max_upgraded_count: Optional[int] = None,
209209
available_resale_amount: Optional[int] = None,
210-
available_amount: Optional[int] = None,
211-
total_amount: Optional[int] = None,
210+
user_limits: Optional["types.GiftPurchaseLimit"] = None,
211+
overall_limits: Optional["types.GiftPurchaseLimit"] = None,
212212
publisher_chat: Optional["types.Chat"] = None,
213+
resale_parameters: Optional["types.GiftResaleParameters"] = None,
213214
can_upgrade: Optional[bool] = None,
214215
can_export_at: Optional[datetime] = None,
215216
can_transfer_at: Optional[datetime] = None,
@@ -222,7 +223,8 @@ def __init__(
222223
is_upgraded: Optional[bool] = None,
223224
is_refunded: Optional[bool] = None,
224225
is_transferred: Optional[bool] = None,
225-
is_birthday: Optional[bool] = None,
226+
is_for_birthday: Optional[bool] = None,
227+
is_premium: Optional[bool] = None,
226228
is_pinned: Optional[bool] = None,
227229
raw: Optional["raw.base.StarGift"] = None
228230
):
@@ -245,19 +247,19 @@ def __init__(
245247
self.convert_price = convert_price
246248
self.upgrade_price = upgrade_price
247249
self.transfer_price = transfer_price
248-
self.resale_price = resale_price
249-
self.last_resale_star_count = last_resale_star_count
250-
self.last_resale_ton_count = last_resale_ton_count
251250
self.upgrade_message_id = upgrade_message_id
252251
self.name = name
253252
self.title = title
254253
self.collectible_id = collectible_id
255254
self.attributes = attributes
256255
self.number = number
256+
self.total_upgraded_count = total_upgraded_count
257+
self.max_upgraded_count = max_upgraded_count
257258
self.available_resale_amount = available_resale_amount
258-
self.available_amount = available_amount
259-
self.total_amount = total_amount
259+
self.user_limits = user_limits
260+
self.overall_limits = overall_limits
260261
self.publisher_chat = publisher_chat
262+
self.resale_parameters = resale_parameters
261263
self.can_upgrade = can_upgrade
262264
self.can_export_at = can_export_at
263265
self.can_transfer_at = can_transfer_at
@@ -270,7 +272,8 @@ def __init__(
270272
self.is_upgraded = is_upgraded
271273
self.is_refunded = is_refunded
272274
self.is_transferred = is_transferred
273-
self.is_birthday = is_birthday
275+
self.is_for_birthday = is_for_birthday
276+
self.is_premium = is_premium
274277
self.is_pinned = is_pinned
275278
self.raw = raw
276279

@@ -304,12 +307,13 @@ async def _parse_regular(
304307
price=star_gift.stars,
305308
convert_price=star_gift.convert_stars,
306309
upgrade_price=star_gift.upgrade_stars,
307-
available_amount=star_gift.availability_remains,
308310
available_resale_amount=star_gift.availability_resale,
309-
total_amount=star_gift.availability_total,
311+
user_limits=types.GiftPurchaseLimit._parse(star_gift.per_user_total, star_gift.per_user_remains),
312+
overall_limits=types.GiftPurchaseLimit._parse(star_gift.availability_total, star_gift.availability_remains),
310313
is_limited=star_gift.limited,
311314
is_sold_out=star_gift.sold_out,
312-
is_birthday=star_gift.birthday,
315+
is_for_birthday=star_gift.birthday,
316+
is_premium=star_gift.require_premium,
313317
first_sale_date=utils.timestamp_to_datetime(star_gift.first_sale_date),
314318
last_sale_date=utils.timestamp_to_datetime(star_gift.last_sale_date),
315319
publisher_chat=types.Chat._parse_chat(client, chats.get(utils.get_raw_peer_id(star_gift.released_by))),
@@ -329,16 +333,6 @@ async def _parse_unique(
329333

330334
owner_id = utils.get_raw_peer_id(star_gift.owner_id)
331335

332-
last_resale_star_count = None
333-
last_resale_ton_count = None
334-
335-
if star_gift.resell_amount:
336-
for currency in star_gift.resell_amount:
337-
if isinstance(currency, raw.types.StarsAmount):
338-
last_resale_star_count = currency.amount
339-
elif isinstance(currency, raw.types.StarsTonAmount):
340-
last_resale_ton_count = currency.amount
341-
342336
return Gift(
343337
id=star_gift.id,
344338
name=star_gift.slug,
@@ -348,13 +342,14 @@ async def _parse_unique(
348342
[await types.GiftAttribute._parse(client, attr, users, chats) for attr in star_gift.attributes]
349343
) or None,
350344
number=star_gift.availability_issued,
351-
total_amount=star_gift.availability_total,
345+
total_upgraded_count=star_gift.availability_total,
346+
max_upgraded_count=star_gift.availability_issued,
347+
is_premium=star_gift.require_premium,
352348
owner=types.Chat._parse_chat(client, users.get(owner_id) or chats.get(owner_id)),
353349
owner_name=star_gift.owner_name,
354350
owner_address=star_gift.owner_address,
355351
gift_address=star_gift.gift_address,
356-
last_resale_star_count=last_resale_star_count,
357-
last_resale_ton_count=last_resale_ton_count,
352+
resale_parameters=types.GiftResaleParameters._parse(star_gift.resell_amount, star_gift.resale_ton_only),
358353
publisher_chat=types.Chat._parse_chat(client, chats.get(utils.get_raw_peer_id(star_gift.released_by))),
359354
is_upgraded=True,
360355
raw=star_gift,
@@ -626,7 +621,7 @@ async def wear(self) -> bool:
626621
)
627622
)
628623

629-
async def buy(self, new_owner_chat_id: Optional[Union[int, str]] = None, star_count: Optional[int] = None) -> Optional["types.Message"]:
624+
async def buy(self, new_owner_chat_id: Optional[Union[int, str]] = None, price: Optional["types.GiftResalePrice"] = None) -> Optional["types.Message"]:
630625
"""Bound method *buy* of :obj:`~pyrogram.types.Gift`.
631626
632627
.. note::
@@ -650,10 +645,16 @@ async def buy(self, new_owner_chat_id: Optional[Union[int, str]] = None, star_co
650645
if new_owner_chat_id is None:
651646
new_owner_chat_id = "me"
652647

648+
if price is None:
649+
if self.resale_parameters.toncoin_only:
650+
price = types.GiftResalePriceTon(toncoin_cent_count=self.resale_parameters.toncoin_cent_count)
651+
else:
652+
price = types.GiftResalePriceStar(star_count=self.resale_parameters.star_count)
653+
653654
return await self._client.send_resold_gift(
654655
gift_link=self.link,
655656
new_owner_chat_id=new_owner_chat_id,
656-
star_count=star_count
657+
price=price
657658
)
658659

659660
async def send(

0 commit comments

Comments
 (0)