Skip to content

Commit d71d968

Browse files
committed
Add set_slow_mode method
1 parent 3c80a10 commit d71d968

5 files changed

Lines changed: 63 additions & 2 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def get_title_list(s: str) -> list:
212212
create_supergroup
213213
delete_channel
214214
delete_supergroup
215+
set_slow_mode
215216
""",
216217
users="""
217218
Users

compiler/error/source/400_BAD_REQUEST.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,4 @@ ADMIN_RANK_EMOJI_NOT_ALLOWED Emojis are not allowed in custom administrator titl
132132
FILE_REFERENCE_EMPTY The file reference is empty
133133
FILE_REFERENCE_INVALID The file reference is invalid
134134
REPLY_MARKUP_TOO_LONG The reply markup is too long
135+
SECONDS_INVALID The seconds interval is invalid, for slow mode try with 0 (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
id message
22
FLOOD_WAIT_X A wait of {x} seconds is required
33
TAKEOUT_INIT_DELAY_X You have to confirm the data export request using one of your mobile devices or wait {x} seconds
4+
SLOWMODE_WAIT_X A wait of {x} seconds is required to send messages in this chat.

pyrogram/client/methods/chats/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from .unban_chat_member import UnbanChatMember
5050
from .unpin_chat_message import UnpinChatMessage
5151
from .update_chat_username import UpdateChatUsername
52-
52+
from .set_slow_mode import SetSlowMode
5353

5454
class Chats(
5555
GetChat,
@@ -84,6 +84,7 @@ class Chats(
8484
DeleteChannel,
8585
DeleteSupergroup,
8686
GetNearbyChats,
87-
SetAdministratorTitle
87+
SetAdministratorTitle,
88+
SetSlowMode
8889
):
8990
pass
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2019 Dan Tès <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.api import functions
22+
from ...ext import BaseClient
23+
24+
25+
class SetSlowMode(BaseClient):
26+
def set_slow_mode(
27+
self,
28+
chat_id: Union[int, str],
29+
seconds: int,
30+
) -> bool:
31+
"""Set the slow mode interval for a chat.
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
37+
seconds (``int`` | ``str``):
38+
Seconds in which members will be able to send only one message per this interval.
39+
Valid values are: 0 (off), 10, 30, 60 (1m), 300 (5m), 900 (15m) or 3600 (1h).
40+
41+
Returns:
42+
``bool``: True on success.
43+
44+
Example:
45+
.. code-block:: python
46+
47+
app.set_slow_mode("pyrogramchat", 60)
48+
"""
49+
50+
self.send(
51+
functions.channels.ToggleSlowMode(
52+
channel=self.resolve_peer(chat_id),
53+
seconds=seconds
54+
)
55+
)
56+
57+
return True

0 commit comments

Comments
 (0)