From b283bce2623d3646f3d785378267e5db271a85ec Mon Sep 17 00:00:00 2001 From: Fernando Werneck Date: Wed, 5 Jan 2022 08:37:25 -0300 Subject: [PATCH 1/2] Add No Forwards chat option (#839) * Add No Forwards chat option * Fix chat.py --- compiler/docs/compiler.py | 1 + pyrogram/methods/chats/__init__.py | 4 +- pyrogram/methods/chats/toggle_no_forwards.py | 49 ++++++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 23 +++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 pyrogram/methods/chats/toggle_no_forwards.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c8823ceb..7becd223 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -515,6 +515,7 @@ def pyrogram_api(): Chat.join Chat.leave Chat.mark_unread + Chat.no_forwards """, user=""" User diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index ce8fe14c..87634793 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -56,6 +56,7 @@ from .unban_chat_member import UnbanChatMember from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername +from .toggle_no_forwards import ToggleNoForwards class Chats( @@ -98,6 +99,7 @@ class Chats( GetChatEventLog, GetChatOnlineCount, GetSendAsChats, - SetSendAsChat + SetSendAsChat, + ToggleNoForwards ): pass diff --git a/pyrogram/methods/chats/toggle_no_forwards.py b/pyrogram/methods/chats/toggle_no_forwards.py new file mode 100644 index 00000000..182c8e77 --- /dev/null +++ b/pyrogram/methods/chats/toggle_no_forwards.py @@ -0,0 +1,49 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2021 Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +from pyrogram.raw import functions +from pyrogram.scaffold import Scaffold + + +class ToggleNoForwards(Scaffold): + async def toggle_no_forwards( + self, + chat_id: Union[int, str], + enabled: bool = False + ) -> bool: + """Toggle no forwards chat option + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + enabled (``bool``, *optional*): + Pass True to enable no forwards + + Returns: + ``bool``: On success, True is returned. + """ + + return await self.send( + functions.messages.ToggleNoForwards( + peer=await self.resolve_peer(chat_id), + enabled=enabled + ) + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 898a4325..8d95e4a9 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -1011,3 +1011,26 @@ class Chat(Object): """ return await self._client.mark_chat_unread(self.id) + + async def no_forwards(self, enabled: bool = False) -> bool: + """Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`. + + Use as a shortcut for: + + .. code-block:: python + + client.toggle_no_forwards(chat_id, enabled) + + Example: + .. code-block:: python + + chat.toggle_no_forwards(True) + + Returns: + ``bool``: On success, True is returned. + """ + + return await self._client.toggle_no_forwards( + self.id, + enabled=enabled + ) From ac3d2b8d7a6e48d9fd304ebc8d3676028f4b2a02 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 5 Jan 2022 12:45:09 +0100 Subject: [PATCH 2/2] Rename methods and add proper docs --- compiler/docs/compiler.py | 3 ++- pyrogram/methods/chats/__init__.py | 4 ++-- ...forwards.py => set_chat_protected_content.py} | 16 +++++++++------- pyrogram/types/user_and_chats/chat.py | 16 ++++++++++------ 4 files changed, 23 insertions(+), 16 deletions(-) rename pyrogram/methods/chats/{toggle_no_forwards.py => set_chat_protected_content.py} (81%) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 7becd223..6dd8adf4 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -226,6 +226,7 @@ def pyrogram_api(): get_chat_online_count get_send_as_chats set_send_as_chat + set_chat_protected_content """, users=""" Users @@ -515,7 +516,7 @@ def pyrogram_api(): Chat.join Chat.leave Chat.mark_unread - Chat.no_forwards + Chat.set_protected_content """, user=""" User diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 87634793..70c02dee 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -48,6 +48,7 @@ from .set_administrator_title import SetAdministratorTitle from .set_chat_description import SetChatDescription from .set_chat_permissions import SetChatPermissions from .set_chat_photo import SetChatPhoto +from .set_chat_protected_content import SetChatProtectedContent from .set_chat_title import SetChatTitle from .set_send_as_chat import SetSendAsChat from .set_slow_mode import SetSlowMode @@ -56,7 +57,6 @@ from .unban_chat_member import UnbanChatMember from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_chat_username import UpdateChatUsername -from .toggle_no_forwards import ToggleNoForwards class Chats( @@ -100,6 +100,6 @@ class Chats( GetChatOnlineCount, GetSendAsChats, SetSendAsChat, - ToggleNoForwards + SetChatProtectedContent ): pass diff --git a/pyrogram/methods/chats/toggle_no_forwards.py b/pyrogram/methods/chats/set_chat_protected_content.py similarity index 81% rename from pyrogram/methods/chats/toggle_no_forwards.py rename to pyrogram/methods/chats/set_chat_protected_content.py index 182c8e77..8057873d 100644 --- a/pyrogram/methods/chats/toggle_no_forwards.py +++ b/pyrogram/methods/chats/set_chat_protected_content.py @@ -22,28 +22,30 @@ from pyrogram.raw import functions from pyrogram.scaffold import Scaffold -class ToggleNoForwards(Scaffold): - async def toggle_no_forwards( +class SetChatProtectedContent(Scaffold): + async def set_chat_protected_content( self, chat_id: Union[int, str], - enabled: bool = False + enabled: bool ) -> bool: - """Toggle no forwards chat option + """Set the chat protected content setting. Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - enabled (``bool``, *optional*): - Pass True to enable no forwards + enabled (``bool``): + Pass True to enable the protected content setting, False to disable. Returns: ``bool``: On success, True is returned. """ - return await self.send( + await self.send( functions.messages.ToggleNoForwards( peer=await self.resolve_peer(chat_id), enabled=enabled ) ) + + return True diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 8d95e4a9..486fe66f 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -325,7 +325,7 @@ class Chat(Object): send_as_raw = users[default_send_as.user_id] else: send_as_raw = chats[default_send_as.channel_id] - + parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw) if full_chat.pinned_msg_id: @@ -1012,25 +1012,29 @@ class Chat(Object): return await self._client.mark_chat_unread(self.id) - async def no_forwards(self, enabled: bool = False) -> bool: - """Bound method *toggle_no_forwards* of :obj:`~pyrogram.types.Chat`. + async def set_protected_content(self, enabled: bool) -> bool: + """Bound method *set_protected_content* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: .. code-block:: python - client.toggle_no_forwards(chat_id, enabled) + client.set_chat_protected_content(chat_id, enabled) + + Parameters: + enabled (``bool``): + Pass True to enable the protected content setting, False to disable. Example: .. code-block:: python - chat.toggle_no_forwards(True) + chat.set_protected_content(enabled) Returns: ``bool``: On success, True is returned. """ - return await self._client.toggle_no_forwards( + return await self._client.set_chat_protected_content( self.id, enabled=enabled )