Skip to content

Commit bb43ab7

Browse files
committed
Add get_owned_star_count method to return the number of stars owned by the current user account
1 parent 24c12e2 commit bb43ab7

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def get_title_list(s: str) -> list:
402402
sell_gift
403403
send_gift
404404
toggle_gift_is_saved
405+
get_owned_star_count
405406
""",
406407
advanced="""
407408
Advanced
@@ -674,6 +675,7 @@ def get_title_list(s: str) -> list:
674675
RefundedPayment
675676
ShippingQuery
676677
PreCheckoutQuery
678+
StarAmount
677679
"""
678680
)
679681

docs/source/releases/changes-in-this-fork.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Changes in this Fork
2525
| Scheme layer used: 196 |
2626
+------------------------+
2727

28+
- Added the :meth:`~pyrogram.Client.get_owned_star_count` and a possibly temporary :obj:`~pyrogram.types.StarAmount`.
2829
- Added the :obj:`~pyrogram.types.UpgradedGift` and changed return type :meth:`~pyrogram.Client.get_available_gifts` and :meth:`~pyrogram.Client.get_user_gifts`.
2930
- Added the ``pay_for_upgrade`` in the :meth:`~pyrogram.Client.send_gift`.
3031
- Added the parameters ``upgrade_star_count`` and ``is_for_birthday`` in :obj:`~pyrogram.types.Gift`.

pyrogram/methods/business/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .get_payment_form import GetPaymentForm
2727
from .send_payment_form import SendPaymentForm
2828
from .get_available_gifts import GetAvailableGifts
29+
from .get_owned_star_count import GetOwnedStarCount
2930
from .get_user_gifts import GetUserGifts
3031
from .sell_gift import SellGift
3132
from .send_gift import SendGift
@@ -43,6 +44,7 @@ class TelegramBusiness(
4344
GetPaymentForm,
4445
SendPaymentForm,
4546
GetAvailableGifts,
47+
GetOwnedStarCount,
4648
GetUserGifts,
4749
SellGift,
4850
SendGift,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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)

pyrogram/types/business/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .shipping_address import ShippingAddress
3030
from .shipping_option import ShippingOption
3131
from .shipping_query import ShippingQuery
32+
from .star_amount import StarAmount
3233
from .successful_payment import SuccessfulPayment
3334
from .refunded_payment import RefundedPayment
3435

@@ -46,6 +47,7 @@
4647
"ShippingAddress",
4748
"ShippingOption",
4849
"ShippingQuery",
50+
"StarAmount",
4951
"SuccessfulPayment",
5052
"RefundedPayment",
5153
]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
import pyrogram
20+
from pyrogram import raw
21+
22+
from ..object import Object
23+
24+
25+
class StarAmount(Object):
26+
"""This object Describes a possibly non-integer amount of Telegram Stars.
27+
28+
Parameters:
29+
star_count (``int``):
30+
The integer amount of Telegram Stars rounded to 0.
31+
32+
nanostar_count (``int``):
33+
The number of 1/1000000000 shares of Telegram Stars; from -999999999 to 999999999.
34+
35+
"""
36+
37+
def __init__(
38+
self,
39+
*,
40+
star_count: int = None,
41+
nanostar_count: int = None,
42+
):
43+
super().__init__()
44+
45+
self.star_count = star_count
46+
self.nanostar_count = nanostar_count
47+
48+
49+
@staticmethod
50+
def _parse(
51+
client: "pyrogram.Client",
52+
stars_status: "raw.base.payments.StarsStatus"
53+
) -> "StarAmount":
54+
return StarAmount(
55+
star_count=stars_status.balance.amount,
56+
nanostar_count=stars_status.balance.nanos,
57+
)

0 commit comments

Comments
 (0)