Skip to content

Commit 153d87c

Browse files
Add edit_user_star_subscription and edit_star_subscription method
Closes #212
1 parent 8cf7eb8 commit 153d87c

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ def get_title_list(s: str) -> list:
449449
create_gift_collection
450450
delete_gift_collection
451451
drop_gift_original_details
452+
edit_star_subscription
452453
get_gift_collections
453454
remove_collection_gifts
454455
reorder_collection_gifts
@@ -497,6 +498,7 @@ def get_title_list(s: str) -> list:
497498
set_bot_commands
498499
get_bot_commands
499500
delete_bot_commands
501+
edit_user_star_subscription
500502
set_bot_default_privileges
501503
get_bot_default_privileges
502504
set_chat_menu_button

pyrogram/methods/bots/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .answer_web_app_query import AnswerWebAppQuery
2424
from .create_invoice_link import CreateInvoiceLink
2525
from .delete_bot_commands import DeleteBotCommands
26+
from .edit_user_star_subscription import EditUserStarSubscription
2627
from .get_bot_commands import GetBotCommands
2728
from .get_bot_default_privileges import GetBotDefaultPrivileges
2829
from .get_bot_info_description import GetBotInfoDescription
@@ -64,6 +65,7 @@ class Bots(
6465
SetBotCommands,
6566
GetBotCommands,
6667
DeleteBotCommands,
68+
EditUserStarSubscription,
6769
SetBotDefaultPrivileges,
6870
SetBotInfoDescription,
6971
SetBotInfoShortDescription,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 Union
20+
21+
import pyrogram
22+
from pyrogram import raw
23+
24+
25+
class EditUserStarSubscription:
26+
async def edit_user_star_subscription(
27+
self: "pyrogram.Client",
28+
user_id: Union[int, str],
29+
telegram_payment_charge_id: str,
30+
is_canceled: bool,
31+
) -> bool:
32+
"""Cancels or re-enables Telegram Star subscription for a user.
33+
34+
.. include:: /_includes/usable-by/bots.rst
35+
36+
Parameters:
37+
user_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the target user.
39+
40+
telegram_payment_charge_id (``str``):
41+
Telegram payment identifier of the subscription.
42+
43+
is_canceled (``bool``):
44+
Pass True to cancel the subscription.
45+
Pass False to allow the user to enable it.
46+
47+
Returns:
48+
``bool``: On success, True is returned.
49+
"""
50+
return await self.invoke(
51+
raw.functions.payments.BotCancelStarsSubscription(
52+
user_id=await self.resolve_peer(user_id),
53+
charge_id=telegram_payment_charge_id,
54+
restore=is_canceled,
55+
)
56+
)

pyrogram/methods/payments/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .create_gift_collection import CreateGiftCollection
2525
from .delete_gift_collection import DeleteGiftCollection
2626
from .drop_gift_original_details import DropGiftOriginalDetails
27+
from .edit_star_subscription import EditStarSubscription
2728
from .get_available_gifts import GetAvailableGifts
2829
from .get_chat_gifts import GetChatGifts
2930
from .get_chat_gifts_count import GetChatGiftsCount
@@ -61,6 +62,7 @@ class Payments(
6162
CreateGiftCollection,
6263
DeleteGiftCollection,
6364
DropGiftOriginalDetails,
65+
EditStarSubscription,
6466
GetAvailableGifts,
6567
GetChatGifts,
6668
GetChatGiftsCount,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
23+
class EditStarSubscription:
24+
async def edit_star_subscription(
25+
self: "pyrogram.Client", subscription_id: str, is_canceled: bool
26+
) -> bool:
27+
"""Cancels or re-enables Telegram Star subscription.
28+
29+
.. include:: /_includes/usable-by/users.rst
30+
31+
Parameters:
32+
subscription_id (``str``):
33+
Identifier of the subscription to change.
34+
35+
is_canceled (``bool``):
36+
New value of is_canceled.
37+
38+
Returns:
39+
``bool``: On success, True is returned.
40+
"""
41+
return await self.invoke(
42+
raw.functions.payments.ChangeStarsSubscription(
43+
peer=raw.types.InputPeerSelf(),
44+
subscription_id=subscription_id,
45+
canceled=is_canceled,
46+
)
47+
)

0 commit comments

Comments
 (0)