mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-06 15:14:52 +00:00
Add get_star_gifts method
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
e4968df4c9
commit
bb96ca8597
5 changed files with 145 additions and 0 deletions
|
|
@ -350,6 +350,7 @@ def pyrogram_api():
|
||||||
check_gift_code
|
check_gift_code
|
||||||
create_invoice_link
|
create_invoice_link
|
||||||
get_payment_form
|
get_payment_form
|
||||||
|
get_star_gifts
|
||||||
get_stars_transactions
|
get_stars_transactions
|
||||||
get_stars_transactions_by_id
|
get_stars_transactions_by_id
|
||||||
refund_star_payment
|
refund_star_payment
|
||||||
|
|
@ -521,6 +522,7 @@ def pyrogram_api():
|
||||||
PollOption
|
PollOption
|
||||||
Dice
|
Dice
|
||||||
Reaction
|
Reaction
|
||||||
|
StarGift
|
||||||
VideoChatScheduled
|
VideoChatScheduled
|
||||||
VideoChatStarted
|
VideoChatStarted
|
||||||
VideoChatEnded
|
VideoChatEnded
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from .apply_gift_code import ApplyGiftCode
|
||||||
from .check_giftcode import CheckGiftCode
|
from .check_giftcode import CheckGiftCode
|
||||||
from .create_invoice_link import CreateInvoiceLink
|
from .create_invoice_link import CreateInvoiceLink
|
||||||
from .get_payment_form import GetPaymentForm
|
from .get_payment_form import GetPaymentForm
|
||||||
|
from .get_star_gifts import GetStarGifts
|
||||||
from .get_stars_transactions import GetStarsTransactions
|
from .get_stars_transactions import GetStarsTransactions
|
||||||
from .get_stars_transactions_by_id import GetStarsTransactionsById
|
from .get_stars_transactions_by_id import GetStarsTransactionsById
|
||||||
from .refund_stars_payment import RefundStarPayment
|
from .refund_stars_payment import RefundStarPayment
|
||||||
|
|
@ -34,6 +35,7 @@ class Payments(
|
||||||
CheckGiftCode,
|
CheckGiftCode,
|
||||||
CreateInvoiceLink,
|
CreateInvoiceLink,
|
||||||
GetPaymentForm,
|
GetPaymentForm,
|
||||||
|
GetStarGifts,
|
||||||
GetStarsTransactions,
|
GetStarsTransactions,
|
||||||
GetStarsTransactionsById,
|
GetStarsTransactionsById,
|
||||||
RefundStarPayment,
|
RefundStarPayment,
|
||||||
|
|
|
||||||
46
pyrogram/methods/payments/get_star_gifts.py
Normal file
46
pyrogram/methods/payments/get_star_gifts.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrofork.
|
||||||
|
#
|
||||||
|
# Pyrofork is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrofork is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, types
|
||||||
|
|
||||||
|
|
||||||
|
class GetStarGifts:
|
||||||
|
async def get_star_gifts(
|
||||||
|
self: "pyrogram.Client",
|
||||||
|
) -> List["types.StarGift"]:
|
||||||
|
"""Get all available star gifts to send.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of :obj:`~pyrogram.types.StarGift`: On success, a list of star gifts is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
app.get_star_gifts()
|
||||||
|
"""
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.payments.GetStarGifts(hash=0)
|
||||||
|
)
|
||||||
|
|
||||||
|
return types.List([await types.StarGift._parse(self, gift) for gift in r.gifts])
|
||||||
|
|
@ -29,6 +29,7 @@ from .payment_form import PaymentForm
|
||||||
from .payment_info import PaymentInfo
|
from .payment_info import PaymentInfo
|
||||||
from .payment_refunded import PaymentRefunded
|
from .payment_refunded import PaymentRefunded
|
||||||
from .purchased_paid_media import PurchasedPaidMedia
|
from .purchased_paid_media import PurchasedPaidMedia
|
||||||
|
from .star_gift import StarGift
|
||||||
from .stars_status import StarsStatus
|
from .stars_status import StarsStatus
|
||||||
from .stars_transaction import StarsTransaction
|
from .stars_transaction import StarsTransaction
|
||||||
from .successful_payment import SuccessfulPayment
|
from .successful_payment import SuccessfulPayment
|
||||||
|
|
@ -46,6 +47,7 @@ __all__ = [
|
||||||
"PaymentInfo",
|
"PaymentInfo",
|
||||||
"PaymentRefunded",
|
"PaymentRefunded",
|
||||||
"PurchasedPaidMedia",
|
"PurchasedPaidMedia",
|
||||||
|
"StarGift",
|
||||||
"StarsStatus",
|
"StarsStatus",
|
||||||
"StarsTransaction",
|
"StarsTransaction",
|
||||||
"SuccessfulPayment"
|
"SuccessfulPayment"
|
||||||
|
|
|
||||||
93
pyrogram/types/payments/star_gift.py
Normal file
93
pyrogram/types/payments/star_gift.py
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import types
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class StarGift(Object):
|
||||||
|
"""A star gift.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
id (``int``):
|
||||||
|
Unique star gift identifier.
|
||||||
|
|
||||||
|
sticker (:obj:`~pyrogram.types.Sticker`):
|
||||||
|
Information about the star gift sticker.
|
||||||
|
|
||||||
|
price (``int``):
|
||||||
|
Price of this gift in stars.
|
||||||
|
|
||||||
|
convert_price (``int``):
|
||||||
|
The number of stars you get if you convert this gift.
|
||||||
|
|
||||||
|
available_amount (``int``, *optional*):
|
||||||
|
The number of gifts available for purchase.
|
||||||
|
Returned only if is_limited is True.
|
||||||
|
|
||||||
|
total_amount (``int``, *optional*):
|
||||||
|
Total amount of gifts.
|
||||||
|
Returned only if is_limited is True.
|
||||||
|
|
||||||
|
is_limited (``bool``, *optional*):
|
||||||
|
True, if the number of gifts is limited.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.Client" = None,
|
||||||
|
id: int,
|
||||||
|
sticker: "types.Sticker",
|
||||||
|
price: int,
|
||||||
|
convert_price: int,
|
||||||
|
available_amount: Optional[int] = None,
|
||||||
|
total_amount: Optional[int] = None,
|
||||||
|
is_limited: Optional[bool] = None,
|
||||||
|
):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.id = id
|
||||||
|
self.sticker = sticker
|
||||||
|
self.price = price
|
||||||
|
self.convert_price = convert_price
|
||||||
|
self.available_amount = available_amount
|
||||||
|
self.total_amount = total_amount
|
||||||
|
self.is_limited = is_limited
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _parse(
|
||||||
|
client,
|
||||||
|
star_gift: "raw.types.StarGift",
|
||||||
|
) -> "StarGift":
|
||||||
|
doc = star_gift.sticker
|
||||||
|
attributes = {type(i): i for i in doc.attributes}
|
||||||
|
|
||||||
|
return StarGift(
|
||||||
|
id=star_gift.id,
|
||||||
|
sticker=await types.Sticker._parse(client, doc, attributes),
|
||||||
|
price=star_gift.stars,
|
||||||
|
convert_price=star_gift.convert_stars,
|
||||||
|
available_amount=getattr(star_gift, "availability_remains", None),
|
||||||
|
total_amount=getattr(star_gift, "availability_total", None),
|
||||||
|
is_limited=getattr(star_gift, "limited", None)
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue