Skip to content

Commit 165c3bb

Browse files
committed
Merge branch 'set-chat-protected-content'
2 parents 1866bfc + 87d8d8b commit 165c3bb

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def get_title_list(s: str) -> list:
226226
get_chat_online_count
227227
get_send_as_chats
228228
set_send_as_chat
229+
set_chat_protected_content
229230
""",
230231
users="""
231232
Users
@@ -515,6 +516,7 @@ def get_title_list(s: str) -> list:
515516
Chat.join
516517
Chat.leave
517518
Chat.mark_unread
519+
Chat.set_protected_content
518520
""",
519521
user="""
520522
User

pyrogram/methods/chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .set_chat_description import SetChatDescription
4949
from .set_chat_permissions import SetChatPermissions
5050
from .set_chat_photo import SetChatPhoto
51+
from .set_chat_protected_content import SetChatProtectedContent
5152
from .set_chat_title import SetChatTitle
5253
from .set_send_as_chat import SetSendAsChat
5354
from .set_slow_mode import SetSlowMode
@@ -98,6 +99,7 @@ class Chats(
9899
GetChatEventLog,
99100
GetChatOnlineCount,
100101
GetSendAsChats,
101-
SetSendAsChat
102+
SetSendAsChat,
103+
SetChatProtectedContent
102104
):
103105
pass
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2021 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+
from pyrogram.raw import functions
22+
from pyrogram.scaffold import Scaffold
23+
24+
25+
class SetChatProtectedContent(Scaffold):
26+
async def set_chat_protected_content(
27+
self,
28+
chat_id: Union[int, str],
29+
enabled: bool
30+
) -> bool:
31+
"""Set the chat protected content setting.
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
37+
enabled (``bool``):
38+
Pass True to enable the protected content setting, False to disable.
39+
40+
Returns:
41+
``bool``: On success, True is returned.
42+
"""
43+
44+
await self.send(
45+
functions.messages.ToggleNoForwards(
46+
peer=await self.resolve_peer(chat_id),
47+
enabled=enabled
48+
)
49+
)
50+
51+
return True

pyrogram/types/user_and_chats/chat.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
331331
send_as_raw = users[default_send_as.user_id]
332332
else:
333333
send_as_raw = chats[default_send_as.channel_id]
334-
334+
335335
parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw)
336336

337337
if full_chat.pinned_msg_id:
@@ -1019,3 +1019,30 @@ async def mark_unread(self, ) -> bool:
10191019
"""
10201020

10211021
return await self._client.mark_chat_unread(self.id)
1022+
1023+
async def set_protected_content(self, enabled: bool) -> bool:
1024+
"""Bound method *set_protected_content* of :obj:`~pyrogram.types.Chat`.
1025+
1026+
Use as a shortcut for:
1027+
1028+
.. code-block:: python
1029+
1030+
client.set_chat_protected_content(chat_id, enabled)
1031+
1032+
Parameters:
1033+
enabled (``bool``):
1034+
Pass True to enable the protected content setting, False to disable.
1035+
1036+
Example:
1037+
.. code-block:: python
1038+
1039+
chat.set_protected_content(enabled)
1040+
1041+
Returns:
1042+
``bool``: On success, True is returned.
1043+
"""
1044+
1045+
return await self._client.set_chat_protected_content(
1046+
self.id,
1047+
enabled=enabled
1048+
)

0 commit comments

Comments
 (0)