diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 8ede4822..414154ed 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -637,6 +637,7 @@ def pyrogram_api(): Chat.unpin_all_messages Chat.mute Chat.unmute + Chat.set_ttl """, user=""" User diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index 36c1788c..66b5d11f 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -58,6 +58,7 @@ 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_chat_ttl import SetChatTTL from .set_chat_username import SetChatUsername from .set_send_as_chat import SetSendAsChat from .set_slow_mode import SetSlowMode @@ -85,6 +86,7 @@ class Chats( DeleteChatPhoto, DeleteFolder, SetChatTitle, + SetChatTTL, SetChatDescription, PinChatMessage, UnpinChatMessage, diff --git a/pyrogram/methods/chats/set_chat_ttl.py b/pyrogram/methods/chats/set_chat_ttl.py new file mode 100644 index 00000000..a1cae1aa --- /dev/null +++ b/pyrogram/methods/chats/set_chat_ttl.py @@ -0,0 +1,64 @@ +# 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 + +import pyrogram +from pyrogram import raw +from pyrogram import types + + +class SetChatTTL: + async def set_chat_ttl( + self: "pyrogram.Client", + chat_id: Union[int, str], + ttl_seconds: int + ) -> "types.Message": + """Set the time-to-live for the chat. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + ttl_seconds (``int``): + The time-to-live for the chat. + Either 86000 for 1 day, 604800 for 1 week or 0 (zero) to disable it. + + Returns: + ``bool``: True on success. + + Example: + .. code-block:: python + + # Set TTL for a chat to 1 day + app.set_chat_ttl(chat_id, 86400) + + # Set TTL for a chat to 1 week + app.set_chat_ttl(chat_id, 604800) + + # Disable TTL for this chat + app.set_chat_ttl(chat_id, 0) + """ + await self.invoke( + raw.functions.messages.SetHistoryTTL( + peer=await self.resolve_peer(chat_id), + period=ttl_seconds, + ) + ) + + return True diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 9ba1cd64..001f570e 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -661,6 +661,31 @@ class Chat(Object): video_start_ts=video_start_ts ) + async def set_ttl(self, ttl_seconds: int) -> bool: + """Bound method *set_ttl* of :obj:`~pyrogram.types.Chat`. + + Use as a shortcut for: + + .. code-block:: python + + await client.set_chat_ttl( + chat_id=chat_id, + ttl_seconds=ttl_seconds + ) + + Example: + .. code-block:: python + + await chat.set_ttl(86400) + + Returns: + ``bool``: True on success. + """ + return await self._client.set_chat_ttl( + chat_id=self.id, + ttl_seconds=ttl_seconds + ) + async def ban_member( self, user_id: Union[int, str],