mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add new method set_chat_ttl
This commit is contained in:
parent
eecf23b2c6
commit
f4d956bb52
@ -637,6 +637,7 @@ def pyrogram_api():
|
||||
Chat.unpin_all_messages
|
||||
Chat.mute
|
||||
Chat.unmute
|
||||
Chat.set_ttl
|
||||
""",
|
||||
user="""
|
||||
User
|
||||
|
@ -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,
|
||||
|
64
pyrogram/methods/chats/set_chat_ttl.py
Normal file
64
pyrogram/methods/chats/set_chat_ttl.py
Normal file
@ -0,0 +1,64 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2021 Dan <https://github.com/delivrance>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
@ -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],
|
||||
|
Loading…
Reference in New Issue
Block a user