From 7cda52ac391693f0bca1ed5babf2ef4dc5c9aad8 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Thu, 9 Jan 2025 08:06:09 +0700 Subject: [PATCH] pyrofork: Add `get_stars_balance` Method Signed-off-by: Yasir --- compiler/docs/compiler.py | 1 + compiler/errors/source/400_BAD_REQUEST.tsv | 3 + pyrogram/methods/payments/__init__.py | 2 + .../methods/payments/get_stars_balance.py | 62 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 pyrogram/methods/payments/get_stars_balance.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index b3a372fb..bf89ffe7 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -368,6 +368,7 @@ def pyrogram_api(): show_gift transfer_gift upgrade_gift + get_stars_balance """, password=""" Password diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index c05fd962..2d75f9cb 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -378,6 +378,9 @@ SLOWMODE_MULTI_MSGS_DISABLED Slowmode is enabled, you cannot forward multiple me SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code SRP_ID_INVALID Invalid SRP ID provided SRP_PASSWORD_CHANGED The password has changed +STARGIFT_ALREADY_CONVERTED The provided star gift already converted to stars +STARGIFT_ALREADY_UPGRADED This star gift was already upgraded before +STARGIFT_USAGE_LIMITED The star gift usage is limited START_PARAM_EMPTY The start parameter is empty START_PARAM_INVALID The start parameter is invalid START_PARAM_TOO_LONG The start parameter is too long diff --git a/pyrogram/methods/payments/__init__.py b/pyrogram/methods/payments/__init__.py index 6540666a..fd0894dc 100644 --- a/pyrogram/methods/payments/__init__.py +++ b/pyrogram/methods/payments/__init__.py @@ -22,6 +22,7 @@ from .check_giftcode import CheckGiftCode from .convert_gift import ConvertGift from .create_invoice_link import CreateInvoiceLink from .get_payment_form import GetPaymentForm +from .get_stars_balance import GetStarsBalance from .get_available_gifts import GetAvailableGifts from .get_stars_transactions import GetStarsTransactions from .get_stars_transactions_by_id import GetStarsTransactionsById @@ -44,6 +45,7 @@ class Payments( ConvertGift, CreateInvoiceLink, GetPaymentForm, + GetStarsBalance, GetAvailableGifts, GetStarsTransactions, GetStarsTransactionsById, diff --git a/pyrogram/methods/payments/get_stars_balance.py b/pyrogram/methods/payments/get_stars_balance.py new file mode 100644 index 00000000..a3832717 --- /dev/null +++ b/pyrogram/methods/payments/get_stars_balance.py @@ -0,0 +1,62 @@ +# 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 . + +from typing import Optional, Union + +import pyrogram +from pyrogram import raw + + +class GetStarsBalance: + async def get_stars_balance( + self: "pyrogram.Client", + chat_id: Optional[Union[int, str]] = None, + ) -> int: + """Get the current Telegram Stars balance of the current account. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + chat_id (``int`` | ``str``, *optional*): + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + + Returns: + ``int``: On success, the current stars balance is returned. + + Example: + .. code-block:: python + + # Get stars balance + app.get_stars_balance() + + # Get stars balance of a bot + app.get_stars_balance(chat_id="pyroforkbot") + """ + if chat_id is None: + peer = raw.types.InputPeerSelf() + else: + peer = await self.resolve_peer(chat_id) + + r = await self.invoke( + raw.functions.payments.GetStarsStatus( + peer=peer + ) + ) + + return r.balance.amount