|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Optional, Union |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw, types |
| 23 | + |
| 24 | + |
| 25 | +class GetOwnedStarCount: |
| 26 | + async def get_owned_star_count( |
| 27 | + self: "pyrogram.Client", |
| 28 | + user_id: Optional[Union[int, str]] = None, |
| 29 | + ) -> "types.StarAmount": |
| 30 | + """Get the number of Telegram Stars count owned by the current account or the specified bot. |
| 31 | +
|
| 32 | + .. include:: /_includes/usable-by/users.rst |
| 33 | +
|
| 34 | + Parameters: |
| 35 | + user_id (``int`` | ``str``, *optional*): |
| 36 | + Unique identifier (int) or username (str) of the bot for which the star count should be returned instead of the current user. |
| 37 | + The bot should have ``can_be_edited`` property set to True. |
| 38 | + Pass ``None`` to return the count of the current user. |
| 39 | +
|
| 40 | + Returns: |
| 41 | + :obj:`~pyrogram.types.StarAmount`: On success, the current stars balance is returned. |
| 42 | +
|
| 43 | + Example: |
| 44 | + .. code-block:: python |
| 45 | +
|
| 46 | + # Get stars balance |
| 47 | + app.get_stars_balance() |
| 48 | +
|
| 49 | + # Get stars balance of a bot owned by the current user |
| 50 | + app.get_stars_balance(user_id="pyrogrambot") |
| 51 | +
|
| 52 | + """ |
| 53 | + if user_id is None: |
| 54 | + peer = raw.types.InputPeerSelf() |
| 55 | + else: |
| 56 | + peer = await self.resolve_peer(user_id) |
| 57 | + |
| 58 | + r = await self.invoke( |
| 59 | + raw.functions.payments.GetStarsStatus( |
| 60 | + peer=peer |
| 61 | + ) |
| 62 | + ) |
| 63 | + |
| 64 | + return types.StarAmount._parse(self, r) |
0 commit comments