MTPyroger/pyrogram/methods/chats/set_slow_mode.py

62 lines
2.0 KiB
Python
Raw Normal View History

2020-03-21 14:43:32 +00:00
# Pyrogram - Telegram MTProto API Client Library for Python
2022-01-07 09:23:45 +00:00
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
2019-10-27 10:02:38 +00:00
#
2020-03-21 14:43:32 +00:00
# This file is part of Pyrogram.
2019-10-27 10:02:38 +00:00
#
2020-03-21 14:43:32 +00:00
# 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.
2019-10-27 10:02:38 +00:00
#
2020-03-21 14:43:32 +00:00
# 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.
2019-10-27 10:02:38 +00:00
#
2020-03-21 14:43:32 +00:00
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
2019-10-27 10:02:38 +00:00
from typing import Union, Optional
2019-10-27 10:02:38 +00:00
from pyrogram import raw
from pyrogram.scaffold import Scaffold
2019-10-27 10:02:38 +00:00
class SetSlowMode(Scaffold):
async def set_slow_mode(
2019-10-27 10:02:38 +00:00
self,
chat_id: Union[int, str],
seconds: Optional[int]
2019-10-27 10:02:38 +00:00
) -> bool:
"""Set the slow mode interval for a chat.
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
2020-07-08 15:16:06 +00:00
seconds (``int`` | ``None``):
2019-10-27 10:02:38 +00:00
Seconds in which members will be able to send only one message per this interval.
2020-07-08 15:16:06 +00:00
Valid values are: 0 or None (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h).
2019-10-27 10:02:38 +00:00
Returns:
``bool``: True on success.
Example:
.. code-block:: python
2020-07-08 15:16:06 +00:00
# Set slow mode to 60 seconds
2022-01-07 09:18:51 +00:00
app.set_slow_mode(chat_id, 60)
2020-07-08 15:16:06 +00:00
# Disable slow mode
2022-01-07 09:18:51 +00:00
app.set_slow_mode(chat_id, None)
2019-10-27 10:02:38 +00:00
"""
await self.send(
raw.functions.channels.ToggleSlowMode(
channel=await self.resolve_peer(chat_id),
2021-03-17 11:37:56 +00:00
seconds=seconds or 0
2019-10-27 10:02:38 +00:00
)
)
return True