Skip to content

Commit 35aee23

Browse files
null-nickwulan17
andcommitted
Topic Impementation by @wulan17
Co-Authored-By: 月 <wulan17@nusantararom.org>
1 parent 2442077 commit 35aee23

44 files changed

Lines changed: 1091 additions & 32 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyrogram/enums/chat_event_action.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,14 @@ class ChatEventAction(AutoName):
123123
MESSAGE_UNPINNED = auto()
124124
"a message has been unpinned (see ``unpinned_message``)"
125125

126+
CREATED_FORUM_TOPIC = auto()
127+
"a new forum topic has been created (see `created_forum_topic`)"
128+
129+
EDITED_FORUM_TOPIC = auto()
130+
"a forum topic has been edited (see `old_forum_topic` and `new_forum_topic`)"
131+
132+
DELETED_FORUM_TOPIC = auto()
133+
"a forum topic has been deleted (see `deleted_forum_topic`)"
134+
126135
UNKNOWN = auto()
127136
"Unknown chat event action"

pyrogram/enums/message_service_type.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ class MessageServiceType(AutoName):
5757
GAME_HIGH_SCORE = auto()
5858
"Game high score"
5959

60+
FORUM_TOPIC_CREATED = auto()
61+
"a new forum topic created in the chat"
62+
63+
FORUM_TOPIC_CLOSED = auto()
64+
"a new forum topic closed in the chat"
65+
66+
FORUM_TOPIC_REOPENED = auto()
67+
"a new forum topic reopened in the chat"
68+
69+
FORUM_TOPIC_EDITED = auto()
70+
"a new forum topic renamed in the chat"
71+
6072
VIDEO_CHAT_STARTED = auto()
6173
"Video chat started"
6274

pyrogram/methods/bots/send_game.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async def send_game(
2929
chat_id: Union[int, str],
3030
game_short_name: str,
3131
disable_notification: bool = None,
32+
message_thread_id: int = None,
3233
reply_to_message_id: int = None,
3334
protect_content: bool = None,
3435
reply_markup: Union[
@@ -55,6 +56,10 @@ async def send_game(
5556
Sends the message silently.
5657
Users will receive a notification with no sound.
5758
59+
message_thread_id (``int``, *optional*):
60+
Unique identifier of a message thread to which the message belongs.
61+
for supergroups only
62+
5863
reply_to_message_id (``int``, *optional*):
5964
If the message is a reply, ID of the original message.
6065
@@ -84,7 +89,7 @@ async def send_game(
8489
),
8590
message="",
8691
silent=disable_notification or None,
87-
reply_to_msg_id=reply_to_message_id,
92+
reply_to_msg_id=reply_to_message_id or message_thread_id,
8893
random_id=self.rnd_id(),
8994
noforwards=protect_content,
9095
reply_markup=await reply_markup.write(self) if reply_markup else None

pyrogram/methods/chats/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
from .archive_chats import ArchiveChats
2121
from .ban_chat_member import BanChatMember
2222
from .create_channel import CreateChannel
23+
from .create_forum_topic import CreateForumTopic
2324
from .create_group import CreateGroup
2425
from .create_group_call import CreateGroupCall
2526
from .create_supergroup import CreateSupergroup
27+
from .close_forum_topic import CloseForumTopic
2628
from .delete_channel import DeleteChannel
2729
from .delete_chat_photo import DeleteChatPhoto
30+
from .delete_forum_topic import DeleteForumTopic
2831
from .delete_supergroup import DeleteSupergroup
2932
from .delete_user_history import DeleteUserHistory
33+
from .edit_forum_topic import EditForumTopic
34+
from .reopen_forum_topic import ReopenForumTopic
3035
from .get_chat import GetChat
3136
from .get_chat_event_log import GetChatEventLog
3237
from .get_chat_member import GetChatMember
@@ -87,9 +92,14 @@ class Chats(
8792
CreateGroup,
8893
CreateSupergroup,
8994
CreateChannel,
95+
CreateForumTopic,
96+
CloseForumTopic,
9097
AddChatMembers,
9198
DeleteChannel,
99+
DeleteForumTopic,
92100
DeleteSupergroup,
101+
EditForumTopic,
102+
ReopenForumTopic,
93103
GetNearbyChats,
94104
SetAdministratorTitle,
95105
SetSlowMode,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
import pyrogram
19+
from pyrogram import raw
20+
from pyrogram import types
21+
from typing import Union
22+
23+
24+
class CloseForumTopic:
25+
async def close_forum_topic(
26+
self: "pyrogram.Client",
27+
chat_id: Union[int, str],
28+
topic_id: int
29+
) -> bool:
30+
"""Close a forum topic.
31+
32+
.. include:: /_includes/usable-by/users-bots.rst
33+
34+
Parameters:
35+
chat_id (``int`` | ``str``):
36+
Unique identifier (int) or username (str) of the target chat.
37+
38+
topic_id (``int``):
39+
Unique identifier (int) of the target forum topic.
40+
41+
Returns:
42+
`bool`: On success, a Boolean is returned.
43+
44+
Example:
45+
.. code-block:: python
46+
47+
await app.close_forum_topic(chat_id, topic_id)
48+
"""
49+
try:
50+
await self.invoke(
51+
raw.functions.channels.EditForumTopic(
52+
channel=await self.resolve_peer(chat_id),
53+
topic_id=topic_id,
54+
closed=True
55+
)
56+
)
57+
except Exception as e:
58+
print(e)
59+
return False
60+
return True
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
import pyrogram
19+
from pyrogram import raw
20+
from pyrogram import types
21+
from typing import Union
22+
23+
24+
class CreateForumTopic:
25+
async def create_forum_topic(
26+
self: "pyrogram.Client",
27+
chat_id: Union[int, str],
28+
title: str,
29+
icon_color: int = None,
30+
icon_emoji_id: int = None
31+
) -> "types.ForumTopicCreated":
32+
"""Create a new forum topic.
33+
34+
.. include:: /_includes/usable-by/users-bots.rst
35+
36+
Parameters:
37+
chat_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the target chat.
39+
40+
title (``str``):
41+
The forum topic title.
42+
43+
icon_color (``int``, *optional*):
44+
The color of forum topic icon.
45+
46+
icon_emoji_id (``int``, *optional*):
47+
Unique identifier of the custom emoji shown as the topic icon
48+
49+
Returns:
50+
:obj:`~pyrogram.types.ForumTopicCreated`: On success, a forum_topic_created object is returned.
51+
52+
Example:
53+
.. code-block:: python
54+
55+
await app.create_forum_topic("Topic Title")
56+
"""
57+
r = await self.invoke(
58+
raw.functions.channels.CreateForumTopic(
59+
channel=await self.resolve_peer(chat_id),
60+
title=title,
61+
random_id=self.rnd_id(),
62+
icon_color=icon_color,
63+
icon_emoji_id=icon_emoji_id
64+
)
65+
)
66+
67+
return types.ForumTopicCreated._parse(r.updates[1].message.action)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
import pyrogram
19+
from pyrogram import raw
20+
from pyrogram import types
21+
from typing import Union
22+
23+
24+
class DeleteForumTopic:
25+
async def delete_forum_topic(
26+
self: "pyrogram.Client",
27+
chat_id: Union[int, str],
28+
topic_id: int
29+
) -> bool:
30+
"""Delete a forum topic.
31+
32+
.. include:: /_includes/usable-by/users-bots.rst
33+
34+
Parameters:
35+
chat_id (``int`` | ``str``):
36+
Unique identifier (int) or username (str) of the target chat.
37+
38+
topic_id (``int``):
39+
Unique identifier (int) of the target forum topic.
40+
41+
Returns:
42+
`bool`: On success, a Boolean is returned.
43+
44+
Example:
45+
.. code-block:: python
46+
47+
await app.delete_forum_topic(chat_id, topic_id)
48+
"""
49+
try:
50+
await self.invoke(
51+
raw.functions.channels.DeleteTopicHistory(
52+
channel=await self.resolve_peer(chat_id),
53+
top_msg_id=topic_id
54+
)
55+
)
56+
except Exception as e:
57+
print(e)
58+
return False
59+
return True
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
import pyrogram
19+
from pyrogram import raw
20+
from pyrogram import types
21+
from typing import Union
22+
23+
24+
class EditForumTopic:
25+
async def edit_forum_topic(
26+
self: "pyrogram.Client",
27+
chat_id: Union[int, str],
28+
topic_id: int,
29+
title: str = None,
30+
icon_emoji_id: int = None
31+
) -> bool:
32+
"""Edit a forum topic.
33+
34+
.. include:: /_includes/usable-by/users-bots.rst
35+
36+
Parameters:
37+
chat_id (``int`` | ``str``):
38+
Unique identifier (int) or username (str) of the target chat.
39+
40+
topic_id (``int``):
41+
Unique identifier (int) of the target forum topic.
42+
43+
title (``str``, *optional*):
44+
The forum topic title.
45+
46+
icon_emoji_id (``int``, *optional*):
47+
Unique identifier of the custom emoji shown as the topic icon
48+
49+
Returns:
50+
`bool`: On success, a Boolean is returned.
51+
52+
Example:
53+
.. code-block:: python
54+
55+
await app.edit_forum_topic(chat_id,topic_id,"New Topic Title")
56+
"""
57+
try:
58+
await self.invoke(
59+
raw.functions.channels.EditForumTopic(
60+
channel=await self.resolve_peer(chat_id),
61+
topic_id=topic_id,
62+
title=title,
63+
icon_emoji_id=icon_emoji_id
64+
)
65+
)
66+
except Exception as e:
67+
print(e)
68+
return False
69+
return True

pyrogram/methods/chats/promote_chat_member.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ async def promote_chat_member(
9292
pin_messages=privileges.can_pin_messages,
9393
add_admins=privileges.can_promote_members,
9494
manage_call=privileges.can_manage_video_chats,
95+
manage_topics=privileges.can_manage_topics,
9596
other=privileges.can_manage_chat
9697
),
9798
rank=rank or ""

0 commit comments

Comments
 (0)