From f38e6a9d1d9658a5f2b1c0f7081e266577cab758 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Fri, 23 May 2025 12:44:14 +0300 Subject: [PATCH] Add transfer_business_account_stars method Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + compiler/errors/source/400_BAD_REQUEST.tsv | 2 + pyrogram/methods/business/__init__.py | 4 +- .../transfer_business_account_stars.py | 72 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/business/transfer_business_account_stars.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index daff224f..5c198847 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -417,6 +417,7 @@ def pyrogram_api(): get_business_connection get_business_account_gifts get_business_account_star_balance + transfer_business_account_stars """, authorization=""" Authorization diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index 2212ec2d..ee599c5f 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -35,6 +35,7 @@ BOT_GAMES_DISABLED Bot games cannot be used in this type of chat BOT_GROUPS_BLOCKED This bot can't be added to groups BOT_INLINE_DISABLED The inline feature of the bot is disabled BOT_INVALID This is not a valid bot +BOT_INVOICE_INVALID The provided invoice is invalid BOT_METHOD_INVALID The method can't be used by bots BOT_MISSING This method can only be run by a bot BOT_ONESIDE_NOT_AVAIL Bots can't pin messages for one side only in private chats @@ -46,6 +47,7 @@ BROADCAST_CALLS_DISABLED Broadcast calls disabled BROADCAST_ID_INVALID The channel is invalid BROADCAST_PUBLIC_VOTERS_FORBIDDEN Polls with public voters cannot be sent in channels BROADCAST_REQUIRED The request can only be used with a channel +BUSINESS_BOT_MISSING Business bot missing BUTTON_DATA_INVALID The button callback data is invalid or too large BUTTON_ID_INVALID The button_id parameter is invalid BUTTON_TEXT_INVALID The specified button text is invalid diff --git a/pyrogram/methods/business/__init__.py b/pyrogram/methods/business/__init__.py index 02123860..cac6b40d 100644 --- a/pyrogram/methods/business/__init__.py +++ b/pyrogram/methods/business/__init__.py @@ -23,6 +23,7 @@ from .delete_business_messages import DeleteBusinessMessages from .get_business_connection import GetBusinessConnection from .get_business_account_gifts import GetBusinessAccountGifts from .get_business_account_star_balance import GetBusinessAccountStarBalance +from .transfer_business_account_stars import TransferBusinessAccountStars class TelegramBusiness( @@ -31,6 +32,7 @@ class TelegramBusiness( DeleteBusinessMessages, GetBusinessConnection, GetBusinessAccountGifts, - GetBusinessAccountStarBalance + GetBusinessAccountStarBalance, + TransferBusinessAccountStars, ): pass diff --git a/pyrogram/methods/business/transfer_business_account_stars.py b/pyrogram/methods/business/transfer_business_account_stars.py new file mode 100644 index 00000000..fbbdc2d0 --- /dev/null +++ b/pyrogram/methods/business/transfer_business_account_stars.py @@ -0,0 +1,72 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +import pyrogram +from pyrogram import raw + + +class TransferBusinessAccountStars: + async def transfer_business_account_stars( + self: "pyrogram.Client", + business_connection_id: str, + star_count: int, + ) -> bool: + """Transfers Telegram Stars from the business account balance to the bot’s balance. + + .. note:: + + Requires the `can_transfer_stars` business bot right. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + business_connection_id (``str``): + Unique identifier of the business connection. + + star_count (``int`` | ``str``): + Number of Telegram Stars to transfer, 1-10000. + + Returns: + ``bool``: On success, True is returned. + """ + # Why telegram won't let us just use InputPeerSelf :( + if self.me: + bot_id = self.me.id + else: + bot_id = ( + await self.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()])) + )[0].id + + invoice = raw.types.InputInvoiceBusinessBotTransferStars( + bot=await self.resolve_peer(bot_id), stars=star_count + ) + + payment_form = await self.invoke( + raw.functions.payments.GetPaymentForm(invoice=invoice), + business_connection_id=business_connection_id, + ) + + await self.invoke( + raw.functions.payments.SendStarsForm( + form_id=payment_form.form_id, + invoice=invoice, + ), + business_connection_id=business_connection_id, + ) + + return True