pyrofork: Add get_stars_balance Method

Signed-off-by: Yasir <git@yasir.id>
This commit is contained in:
KurimuzonAkuma 2025-01-09 08:06:09 +07:00 committed by Yasir
parent 7404c46d7d
commit 7cda52ac39
4 changed files with 68 additions and 0 deletions

View file

@ -368,6 +368,7 @@ def pyrogram_api():
show_gift show_gift
transfer_gift transfer_gift
upgrade_gift upgrade_gift
get_stars_balance
""", """,
password=""" password="""
Password Password

View file

@ -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 SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code
SRP_ID_INVALID Invalid SRP ID provided SRP_ID_INVALID Invalid SRP ID provided
SRP_PASSWORD_CHANGED The password has changed 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_EMPTY The start parameter is empty
START_PARAM_INVALID The start parameter is invalid START_PARAM_INVALID The start parameter is invalid
START_PARAM_TOO_LONG The start parameter is too long START_PARAM_TOO_LONG The start parameter is too long

1 id message
378 SMS_CODE_CREATE_FAILED An error occurred while creating the SMS code
379 SRP_ID_INVALID Invalid SRP ID provided
380 SRP_PASSWORD_CHANGED The password has changed
381 STARGIFT_ALREADY_CONVERTED The provided star gift already converted to stars
382 STARGIFT_ALREADY_UPGRADED This star gift was already upgraded before
383 STARGIFT_USAGE_LIMITED The star gift usage is limited
384 START_PARAM_EMPTY The start parameter is empty
385 START_PARAM_INVALID The start parameter is invalid
386 START_PARAM_TOO_LONG The start parameter is too long

View file

@ -22,6 +22,7 @@ from .check_giftcode import CheckGiftCode
from .convert_gift import ConvertGift from .convert_gift import ConvertGift
from .create_invoice_link import CreateInvoiceLink from .create_invoice_link import CreateInvoiceLink
from .get_payment_form import GetPaymentForm from .get_payment_form import GetPaymentForm
from .get_stars_balance import GetStarsBalance
from .get_available_gifts import GetAvailableGifts from .get_available_gifts import GetAvailableGifts
from .get_stars_transactions import GetStarsTransactions from .get_stars_transactions import GetStarsTransactions
from .get_stars_transactions_by_id import GetStarsTransactionsById from .get_stars_transactions_by_id import GetStarsTransactionsById
@ -44,6 +45,7 @@ class Payments(
ConvertGift, ConvertGift,
CreateInvoiceLink, CreateInvoiceLink,
GetPaymentForm, GetPaymentForm,
GetStarsBalance,
GetAvailableGifts, GetAvailableGifts,
GetStarsTransactions, GetStarsTransactions,
GetStarsTransactionsById, GetStarsTransactionsById,

View file

@ -0,0 +1,62 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
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