mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add get_star_gifts method
This commit is contained in:
parent
fa287076eb
commit
0293a5e0f4
@ -323,6 +323,7 @@ def pyrogram_api():
|
||||
apply_gift_code
|
||||
check_gift_code
|
||||
get_payment_form
|
||||
get_star_gifts
|
||||
send_payment_form
|
||||
""",
|
||||
phone="""
|
||||
@ -517,6 +518,7 @@ def pyrogram_api():
|
||||
PollOption
|
||||
Dice
|
||||
Reaction
|
||||
StarGift
|
||||
VideoChatScheduled
|
||||
VideoChatStarted
|
||||
VideoChatEnded
|
||||
|
@ -19,12 +19,14 @@
|
||||
from .apply_gift_code import ApplyGiftCode
|
||||
from .check_gift_code import CheckGiftCode
|
||||
from .get_payment_form import GetPaymentForm
|
||||
from .get_star_gifts import GetStarGifts
|
||||
from .send_payment_form import SendPaymentForm
|
||||
|
||||
class Payments(
|
||||
ApplyGiftCode,
|
||||
CheckGiftCode,
|
||||
GetPaymentForm,
|
||||
GetStarGifts,
|
||||
SendPaymentForm
|
||||
):
|
||||
pass
|
||||
|
44
pyrogram/methods/payments/get_star_gifts.py
Normal file
44
pyrogram/methods/payments/get_star_gifts.py
Normal file
@ -0,0 +1,44 @@
|
||||
# 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 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])
|
@ -50,6 +50,7 @@ from .photo import Photo
|
||||
from .poll import Poll
|
||||
from .poll_option import PollOption
|
||||
from .reaction import Reaction
|
||||
from .star_gift import StarGift
|
||||
from .sticker import Sticker
|
||||
from .story import Story
|
||||
from .stripped_thumbnail import StrippedThumbnail
|
||||
@ -97,6 +98,7 @@ __all__ = [
|
||||
"Poll",
|
||||
"PollOption",
|
||||
"Reaction",
|
||||
"StarGift",
|
||||
"Sticker",
|
||||
"Story",
|
||||
"StrippedThumbnail",
|
||||
|
93
pyrogram/types/messages_and_media/star_gift.py
Normal file
93
pyrogram/types/messages_and_media/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 New Issue
Block a user