From f23f450c6248e632a9cf5004565bd75f42985524 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Mon, 7 Oct 2024 10:08:35 +0300 Subject: [PATCH] Add convert_star_gift method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + pyrogram/methods/payments/__init__.py | 6 ++ .../methods/payments/convert_star_gift.py | 71 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 pyrogram/methods/payments/convert_star_gift.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index b07a47d7..7372202b 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -348,6 +348,7 @@ def pyrogram_api(): Payments apply_gift_code check_gift_code + convert_star_gift create_invoice_link get_payment_form get_star_gifts diff --git a/pyrogram/methods/payments/__init__.py b/pyrogram/methods/payments/__init__.py index b3c8a2ed..8209ddb4 100644 --- a/pyrogram/methods/payments/__init__.py +++ b/pyrogram/methods/payments/__init__.py @@ -18,8 +18,13 @@ # along with Pyrofork. If not, see . from .apply_gift_code import ApplyGiftCode +<<<<<<< HEAD from .check_giftcode import CheckGiftCode from .create_invoice_link import CreateInvoiceLink +======= +from .check_gift_code import CheckGiftCode +from .convert_star_gift import ConvertStarGift +>>>>>>> 1473842c6 (Add convert_star_gift method) from .get_payment_form import GetPaymentForm from .get_star_gifts import GetStarGifts from .get_stars_transactions import GetStarsTransactions @@ -34,6 +39,7 @@ from .send_star_gift import SendStarGift class Payments( ApplyGiftCode, CheckGiftCode, + ConvertStarGift, CreateInvoiceLink, GetPaymentForm, GetStarGifts, diff --git a/pyrogram/methods/payments/convert_star_gift.py b/pyrogram/methods/payments/convert_star_gift.py new file mode 100644 index 00000000..4e2724c4 --- /dev/null +++ b/pyrogram/methods/payments/convert_star_gift.py @@ -0,0 +1,71 @@ +# 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 Union + +import pyrogram +from pyrogram import raw + + +class ConvertStarGift: + async def convert_star_gift( + self: "pyrogram.Client", + chat_id: Union[int, str], + message_id: int + ) -> bool: + """Convert star gift to stars. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + + message_id (``int``): + Unique message identifier of star gift. + + Returns: + ``bool``: On success, True is returned. + + Example: + .. code-block:: python + + # Convert gift + app.convert_star_gift(chat_id=chat_id, message_id=123) + """ + peer = await self.resolve_peer(chat_id) + + if isinstance(peer, raw.types.InputPeerUser): + peer = raw.types.InputUser(user_id=peer.user_id, access_hash=peer.access_hash) + elif isinstance(peer, raw.types.InputPeerSelf): + peer = raw.types.InputUserSelf() + else: + raise ValueError("chat_id must belong to a user.") + + r = await self.invoke( + raw.functions.payments.ConvertStarGift( + user_id=peer, + msg_id=message_id + ) + ) + + return r