pyrofork: Add get_collectible_item_info

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
Zaid _ 2024-06-01 22:02:07 +07:00 committed by wulan17
parent ebbd5dd0bb
commit fac571aff9
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
5 changed files with 144 additions and 1 deletions

View file

@ -360,6 +360,7 @@ def pyrogram_api():
answer_pre_checkout_query
get_bot_info
set_bot_info
get_collectible_item_info
""",
authorization="""
Authorization
@ -455,6 +456,7 @@ def pyrogram_api():
PeerChannel
BotInfo
ChatColor
CollectibleItemInfo
""",
messages_media="""
Messages & Media

View file

@ -26,6 +26,7 @@ from .get_bot_commands import GetBotCommands
from .get_bot_default_privileges import GetBotDefaultPrivileges
from .get_bot_info import GetBotInfo
from .get_chat_menu_button import GetChatMenuButton
from .get_collectible_item_info import GetCollectibleItemInfo
from .get_game_high_scores import GetGameHighScores
from .get_inline_bot_results import GetInlineBotResults
from .request_callback_answer import RequestCallbackAnswer
@ -57,6 +58,7 @@ class Bots(
SetChatMenuButton,
GetChatMenuButton,
AnswerWebAppQuery,
AnswerPreCheckoutQuery
AnswerPreCheckoutQuery,
GetCollectibleItemInfo
):
pass

View file

@ -0,0 +1,63 @@
# 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/>.
import pyrogram
from pyrogram import raw, types
class GetCollectibleItemInfo:
async def get_collectible_item_info(
self: "pyrogram.Client",
username: str = None,
phone_number: str = None
) -> "types.CollectibleInfo":
"""Returns information about a given collectible item that was purchased at https://fragment.com
.. include:: /_includes/usable-by/users.rst
You must use exactly one of ``username`` OR ``phone_number``.
Parameters:
username (``str``, *optional*):
Describes a collectible username that can be purchased at https://fragment.com
phone_number (``str``, *optional*):
Describes a collectible phone number that can be purchased at https://fragment.com
Returns:
:obj:`~pyrogram.types.CollectibleInfo`: On success, a collectible info is returned.
Example:
.. code-block:: python
username = await app.get_collectible_item_info(username="nerd")
print(username)
"""
input_collectible = None
if username:
input_collectible = raw.types.InputCollectibleUsername(username=username)
elif phone_number:
input_collectible = raw.types.InputCollectiblePhone(phone=phone_number)
else:
raise ValueError(
"No argument supplied. Either pass username OR phone_number"
)
r = await self.invoke(
raw.functions.fragment.GetCollectibleInfo(
collectible=input_collectible
)
)
return types.CollectibleItemInfo._parse(r)

View file

@ -30,6 +30,7 @@ from .bot_command_scope_default import BotCommandScopeDefault
from .bot_info import BotInfo
from .callback_game import CallbackGame
from .callback_query import CallbackQuery
from .collectible_item_info import CollectibleItemInfo
from .force_reply import ForceReply
from .game_high_score import GameHighScore
from .inline_keyboard_button import InlineKeyboardButton
@ -56,6 +57,7 @@ __all__ = [
"BotBusinessConnection",
"CallbackGame",
"CallbackQuery",
"CollectibleItemInfo",
"ForceReply",
"GameHighScore",
"InlineKeyboardButton",

View file

@ -0,0 +1,74 @@
# 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 datetime import datetime
from pyrogram import raw, utils
from ..object import Object
class CollectibleItemInfo(Object):
"""Contains information about a collectible item and its last purchase.
Parameters:
purchase_date (``datetime``):
Point in time (Unix timestamp) when the item was purchased
currency (``str``):
Currency for the paid amount
amount (``float``):
The paid amount, in the smallest units of the currency
cryptocurrency (``str``):
Cryptocurrency used to pay for the item
cryptocurrency_amount (``float``):
The paid amount, in the smallest units of the cryptocurrency
url (``str``):
Individual URL for the item on https://fragment.com
"""
def __init__(
self,
*,
purchase_date : datetime,
currency : str,
amount: float,
cryptocurrency: str,
cryptocurrency_amount: float,
url: str
):
super().__init__()
self.purchase_date = purchase_date
self.currency= currency
self.amount = amount
self.cryptocurrency = cryptocurrency
self.cryptocurrency_amount = cryptocurrency_amount
self.url = url
@staticmethod
def _parse(
collectible_info: "raw.types.fragment.CollectibleInfo"
) -> "CollectibleItemInfo":
return CollectibleItemInfo(
purchase_date=utils.timestamp_to_datetime(collectible_info.purchase_date),
currency=collectible_info.currency,
amount=collectible_info.amount,
cryptocurrency=collectible_info.crypto_currency,
cryptocurrency_amount=collectible_info.crypto_amount,
url=collectible_info.url
)