diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 99f63d0f..2536e1bb 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -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 diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index c2af56d5..f37303d1 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -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 diff --git a/pyrogram/methods/bots/get_collectible_item_info.py b/pyrogram/methods/bots/get_collectible_item_info.py new file mode 100644 index 00000000..e96f7313 --- /dev/null +++ b/pyrogram/methods/bots/get_collectible_item_info.py @@ -0,0 +1,63 @@ +# 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 . + +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) diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 228389b2..f37624f2 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -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", diff --git a/pyrogram/types/bots_and_keyboards/collectible_item_info.py b/pyrogram/types/bots_and_keyboards/collectible_item_info.py new file mode 100644 index 00000000..66d96045 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/collectible_item_info.py @@ -0,0 +1,74 @@ +# 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 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 + ) \ No newline at end of file