Skip to content

Commit 9633fa8

Browse files
Add toggle_forum_topics method
1 parent 3c6dfed commit 9633fa8

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

pyrogram/methods/chats/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from .set_chat_username import SetChatUsername
5858
from .set_send_as_chat import SetSendAsChat
5959
from .set_slow_mode import SetSlowMode
60+
from .toggle_forum_topics import ToggleForumTopics
6061
from .unarchive_chats import UnarchiveChats
6162
from .unban_chat_member import UnbanChatMember
6263
from .unpin_all_chat_messages import UnpinAllChatMessages
@@ -105,6 +106,7 @@ class Chats(
105106
GetNearbyChats,
106107
SetAdministratorTitle,
107108
SetSlowMode,
109+
ToggleForumTopics,
108110
DeleteUserHistory,
109111
UnpinAllChatMessages,
110112
MarkChatUnread,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
from pyrogram import errors
24+
25+
26+
class ToggleForumTopics:
27+
async def toggle_forum_topics(
28+
self: "pyrogram.Client",
29+
chat_id: Union[int, str],
30+
enabled: bool = False
31+
) -> bool:
32+
"""Enable or disable forum functionality in a supergroup.
33+
34+
.. include:: /_includes/usable-by/users.rst
35+
36+
Parameters:
37+
chat_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the target chat.
39+
40+
enabled (``bool``):
41+
The new status. Pass True to enable forum topics.
42+
43+
Returns:
44+
``bool``: True on success. False otherwise.
45+
46+
Example:
47+
.. code-block:: python
48+
49+
# Change status of topics to disabled
50+
await app.toggle_topics()
51+
52+
# Change status of topics to enabled
53+
await app.toggle_topics(enabled=True)
54+
"""
55+
try:
56+
r = await self.invoke(
57+
raw.functions.channels.ToggleForum(
58+
channel=await self.resolve_peer(chat_id),
59+
enabled=enabled
60+
)
61+
)
62+
63+
return bool(r)
64+
except errors.RPCError:
65+
return False

0 commit comments

Comments
 (0)