Skip to content

Commit b283bce

Browse files
Add No Forwards chat option (pyrogram#839)
* Add No Forwards chat option * Fix chat.py
1 parent 00c9112 commit b283bce

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ def get_title_list(s: str) -> list:
515515
Chat.join
516516
Chat.leave
517517
Chat.mark_unread
518+
Chat.no_forwards
518519
""",
519520
user="""
520521
User

pyrogram/methods/chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from .unpin_all_chat_messages import UnpinAllChatMessages
5757
from .unpin_chat_message import UnpinChatMessage
5858
from .update_chat_username import UpdateChatUsername
59+
from .toggle_no_forwards import ToggleNoForwards
5960

6061

6162
class Chats(
@@ -98,6 +99,7 @@ class Chats(
9899
GetChatEventLog,
99100
GetChatOnlineCount,
100101
GetSendAsChats,
101-
SetSendAsChat
102+
SetSendAsChat,
103+
ToggleNoForwards
102104
):
103105
pass
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 ToggleNoForwards(Scaffold):
26+
async def toggle_no_forwards(
27+
self,
28+
chat_id: Union[int, str],
29+
enabled: bool = False
30+
) -> bool:
31+
"""Toggle no forwards chat option
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
37+
enabled (``bool``, *optional*):
38+
Pass True to enable no forwards
39+
40+
Returns:
41+
``bool``: On success, True is returned.
42+
"""
43+
44+
return await self.send(
45+
functions.messages.ToggleNoForwards(
46+
peer=await self.resolve_peer(chat_id),
47+
enabled=enabled
48+
)
49+
)

pyrogram/types/user_and_chats/chat.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,3 +1011,26 @@ async def mark_unread(self, ) -> bool:
10111011
"""
10121012

10131013
return await self._client.mark_chat_unread(self.id)
1014+
1015+
async def no_forwards(self, enabled: bool = False) -> bool:
1016+
"""Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`.
1017+
1018+
Use as a shortcut for:
1019+
1020+
.. code-block:: python
1021+
1022+
client.toggle_no_forwards(chat_id, enabled)
1023+
1024+
Example:
1025+
.. code-block:: python
1026+
1027+
chat.toggle_no_forwards(True)
1028+
1029+
Returns:
1030+
``bool``: On success, True is returned.
1031+
"""
1032+
1033+
return await self._client.toggle_no_forwards(
1034+
self.id,
1035+
enabled=enabled
1036+
)

0 commit comments

Comments
 (0)