From bb96ca85974bae559d956df581e829e67463eeac Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Mon, 7 Oct 2024 09:17:50 +0300 Subject: [PATCH] Add get_star_gifts method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 2 + pyrogram/methods/payments/__init__.py | 2 + pyrogram/methods/payments/get_star_gifts.py | 46 ++++++++++ pyrogram/types/payments/__init__.py | 2 + pyrogram/types/payments/star_gift.py | 93 +++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 pyrogram/methods/payments/get_star_gifts.py create mode 100644 pyrogram/types/payments/star_gift.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index db13de79..1cf5c854 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -350,6 +350,7 @@ def pyrogram_api(): check_gift_code create_invoice_link get_payment_form + get_star_gifts get_stars_transactions get_stars_transactions_by_id refund_star_payment @@ -521,6 +522,7 @@ def pyrogram_api(): PollOption Dice Reaction + StarGift VideoChatScheduled VideoChatStarted VideoChatEnded diff --git a/pyrogram/methods/payments/__init__.py b/pyrogram/methods/payments/__init__.py index aa38ad56..ebd293f1 100644 --- a/pyrogram/methods/payments/__init__.py +++ b/pyrogram/methods/payments/__init__.py @@ -21,6 +21,7 @@ from .apply_gift_code import ApplyGiftCode from .check_giftcode import CheckGiftCode from .create_invoice_link import CreateInvoiceLink from .get_payment_form import GetPaymentForm +from .get_star_gifts import GetStarGifts from .get_stars_transactions import GetStarsTransactions from .get_stars_transactions_by_id import GetStarsTransactionsById from .refund_stars_payment import RefundStarPayment @@ -34,6 +35,7 @@ class Payments( CheckGiftCode, CreateInvoiceLink, GetPaymentForm, + GetStarGifts, GetStarsTransactions, GetStarsTransactionsById, RefundStarPayment, diff --git a/pyrogram/methods/payments/get_star_gifts.py b/pyrogram/methods/payments/get_star_gifts.py new file mode 100644 index 00000000..d5d8da16 --- /dev/null +++ b/pyrogram/methods/payments/get_star_gifts.py @@ -0,0 +1,46 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present 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 . + +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]) diff --git a/pyrogram/types/payments/__init__.py b/pyrogram/types/payments/__init__.py index 7c6dd85f..eda00330 100644 --- a/pyrogram/types/payments/__init__.py +++ b/pyrogram/types/payments/__init__.py @@ -29,6 +29,7 @@ from .payment_form import PaymentForm from .payment_info import PaymentInfo from .payment_refunded import PaymentRefunded from .purchased_paid_media import PurchasedPaidMedia +from .star_gift import StarGift from .stars_status import StarsStatus from .stars_transaction import StarsTransaction from .successful_payment import SuccessfulPayment @@ -46,6 +47,7 @@ __all__ = [ "PaymentInfo", "PaymentRefunded", "PurchasedPaidMedia", + "StarGift", "StarsStatus", "StarsTransaction", "SuccessfulPayment" diff --git a/pyrogram/types/payments/star_gift.py b/pyrogram/types/payments/star_gift.py new file mode 100644 index 00000000..a17780b9 --- /dev/null +++ b/pyrogram/types/payments/star_gift.py @@ -0,0 +1,93 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +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) + )