From 56621a6f4de456d91f9e5153fc032925a7d7023f Mon Sep 17 00:00:00 2001 From: wulan17 Date: Thu, 1 Aug 2024 01:58:36 +0700 Subject: [PATCH] pyrofork: Add get_stars_transaction_by_id method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 2 + pyrogram/methods/business/__init__.py | 4 +- .../business/get_stars_transactions_by_id.py | 87 +++++++++++++++++++ pyrogram/types/business/__init__.py | 2 + .../types/business/input_stars_transaction.py | 49 +++++++++++ 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/business/get_stars_transactions_by_id.py create mode 100644 pyrogram/types/business/input_stars_transaction.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index f7a2bec6..72f821a8 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -379,6 +379,7 @@ def pyrogram_api(): create_invoice_link get_business_connection get_stars_transactions + get_stars_transactions_by_id """, authorization=""" Authorization @@ -601,6 +602,7 @@ def pyrogram_api(): """, business=""" Telegram Business + InputStarsTransaction StarsStatus StarsTransaction """, diff --git a/pyrogram/methods/business/__init__.py b/pyrogram/methods/business/__init__.py index fb84b372..cf0e4dde 100644 --- a/pyrogram/methods/business/__init__.py +++ b/pyrogram/methods/business/__init__.py @@ -19,11 +19,13 @@ from .create_invoice_link import CreateInvoiceLink from .get_business_connection import GetBusinessConnection from .get_stars_transactions import GetStarsTransactions +from .get_stars_transactions_by_id import GetStarsTransactionsById class TelegramBusiness( CreateInvoiceLink, GetBusinessConnection, - GetStarsTransactions + GetStarsTransactions, + GetStarsTransactionsById ): pass diff --git a/pyrogram/methods/business/get_stars_transactions_by_id.py b/pyrogram/methods/business/get_stars_transactions_by_id.py new file mode 100644 index 00000000..427dc381 --- /dev/null +++ b/pyrogram/methods/business/get_stars_transactions_by_id.py @@ -0,0 +1,87 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# 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 +from pyrogram import types +from typing import Union, List + + +class GetStarsTransactionsById: + async def get_stars_transactions_by_id( + self: "pyrogram.Client", + transaction_ids: Union[ + "types.InputStarsTransaction", + List["types.InputStarsTransaction"] + ], + chat_id: Union[int, str] = "me" + ) -> "types.StarsStatus": + """Get stars transactions by transaction id. + + .. include:: /_includes/usable-by/users-bots.rst + + Parameters: + transaction_ids (:obj:`~pyrogram.types.InputStarsTransaction` | List of :obj:`~pyrogram.types.InputStarsTransaction`): + Pass a single transaction identifier or an iterable of transaction ids (as integers) to get the content of the + transaction themselves + + chat_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the target user. + You can also use chat public link in form of *t.me/* (str). + default to self. + only for bots. + + Example: + .. code-block:: python + + # get one transaction by id + from pyrogram.types import InputStarsTransaction + app.get_stars_transactions_by_id(InputStarsTransaction(id="transaction_id")) + + # get multiple transactions by id + from pyrogram.types import InputStarsTransaction + app.get_stars_transactions_by_id([ + InputStarsTransaction(id="transaction_id_1"), + InputStarsTransaction(id="transaction_id_2") + ]) + + # get one transaction by id from a specific user + from pyrogram.types import InputStarsTransaction + app.get_stars_transactions_by_id(InputStarsTransaction(id="transaction_id"), chat_id="username") + + # get multiple transaction by id from a specific user + from pyrogram.types import InputStarsTransaction + app.get_stars_transactions_by_id([ + InputStarsTransaction(id="transaction_id_1"), + InputStarsTransaction(id="transaction_id_2") + ], chat_id="username") + + Returns: + :obj:`~pyrogram.types.StarsStatus`: On success, a :obj:`~pyrogram.types.StarsStatus` object is returned. + """ + peer = await self.resolve_peer(chat_id) + is_iterable = not isinstance(transaction_ids, types.InputStarsTransaction) + ids = [await transaction_ids.write()] if not is_iterable else [await x.write() for x in transaction_ids] + + r = await self.invoke( + raw.functions.payments.GetStarsTransactionsByID( + peer=peer, + id=ids + ) + ) + return types.StarsStatus._parse(self, r) diff --git a/pyrogram/types/business/__init__.py b/pyrogram/types/business/__init__.py index 84e2b25a..6c2d5df5 100644 --- a/pyrogram/types/business/__init__.py +++ b/pyrogram/types/business/__init__.py @@ -16,10 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . +from .input_stars_transaction import InputStarsTransaction from .stars_status import StarsStatus from .stars_transaction import StarsTransaction __all__ = [ + "InputStarsTransaction", "StarsStatus", "StarsTransaction" ] diff --git a/pyrogram/types/business/input_stars_transaction.py b/pyrogram/types/business/input_stars_transaction.py new file mode 100644 index 00000000..156d2c45 --- /dev/null +++ b/pyrogram/types/business/input_stars_transaction.py @@ -0,0 +1,49 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# 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 +from ..object import Object + +class InputStarsTransaction(Object): + """Content of a stars transaction. + + Parameters: + id (``str``): + Unique transaction identifier. + + is_refund (``bool``, *optional*): + True, If the transaction is a refund. + """ + def __init__( + self, + *, + id: str, + is_refund: bool = None + ): + super().__init__() + + self.id = id + self.is_refund = is_refund + + async def write(self): + return raw.types.InputStarsTransaction( + id=self.id, + refund=self.is_refund + )