Add sleep_threshold parameter to send() method · pythonfansx/pyrogram@7c98788 · GitHub
Skip to content

Commit 7c98788

Browse files
committed
Add sleep_threshold parameter to send() method
- Decrease the default sleep threshold from 60 to 10 seconds - Use a higher sleep threshold for generator methods
1 parent ebf222b commit 7c98788

10 files changed

Lines changed: 34 additions & 17 deletions

File tree

pyrogram/client.py

Lines changed: 1 addition & 1 deletion

pyrogram/methods/advanced/send.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727

2828

2929
class Send(Scaffold):
30-
async def send(self, data: TLObject, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT):
30+
async def send(
31+
self,
32+
data: TLObject,
33+
retries: int = Session.MAX_RETRIES,
34+
timeout: float = Session.WAIT_TIMEOUT,
35+
sleep_threshold: float = None
36+
):
3137
"""Send raw Telegram queries.
3238
3339
This method makes it possible to manually call every single Telegram API method in a low-level manner.
@@ -50,6 +56,9 @@ async def send(self, data: TLObject, retries: int = Session.MAX_RETRIES, timeout
5056
timeout (``float``):
5157
Timeout in seconds.
5258
59+
sleep_threshold (``float``):
60+
Sleep threshold in seconds.
61+
5362
Returns:
5463
``RawType``: The raw type response generated by the query.
5564
@@ -65,7 +74,7 @@ async def send(self, data: TLObject, retries: int = Session.MAX_RETRIES, timeout
6574
if self.takeout_id:
6675
data = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data)
6776

68-
r = await self.session.send(data, retries, timeout, self.sleep_threshold)
77+
r = await self.session.send(data, retries, timeout, sleep_threshold or self.sleep_threshold)
6978

7079
await self.fetch_peers(getattr(r, "users", []))
7180
await self.fetch_peers(getattr(r, "chats", []))

pyrogram/methods/chats/get_chat_members.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ async def get_chat_members(
141141
offset=offset,
142142
limit=limit,
143143
hash=0
144-
)
144+
),
145+
sleep_threshold=60
145146
)
146147

147148
members = r.participants

pyrogram/methods/chats/get_dialogs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ async def get_dialogs(
6666
"""
6767

6868
if pinned_only:
69-
r = await self.send(raw.functions.messages.GetPinnedDialogs(folder_id=0))
69+
r = await self.send(
70+
raw.functions.messages.GetPinnedDialogs(folder_id=0),
71+
sleep_threshold=60
72+
)
7073
else:
7174
r = await self.send(
7275
raw.functions.messages.GetDialogs(
@@ -76,7 +79,8 @@ async def get_dialogs(
7679
limit=limit,
7780
hash=0,
7881
exclude_pinned=True
79-
)
82+
),
83+
sleep_threshold=60
8084
)
8185

8286
users = {i.id: i for i in r.users}

pyrogram/methods/messages/get_history.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import Union, List
2121

2222
from pyrogram import raw
23-
# from pyrogram import types
23+
from pyrogram import types
2424
from pyrogram import utils
2525
from pyrogram.scaffold import Scaffold
2626

@@ -95,7 +95,8 @@ async def get_history(
9595
max_id=0,
9696
min_id=0,
9797
hash=0
98-
)
98+
),
99+
sleep_threshold=60
99100
)
100101
)
101102

pyrogram/methods/messages/get_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def get_messages(
111111
else:
112112
rpc = raw.functions.messages.GetMessages(id=ids)
113113

114-
r = await self.send(rpc)
114+
r = await self.send(rpc, sleep_threshold=-1)
115115

116116
messages = await utils.parse_messages(self, r, replies=replies)
117117

pyrogram/methods/messages/search_global.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ async def search_global(
7474
offset_peer=offset_peer,
7575
offset_id=offset_id,
7676
limit=limit
77-
)
77+
),
78+
sleep_threshold=60
7879
),
7980
replies=0
8081
)

pyrogram/methods/messages/search_messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ async def get_chunk(
8080
else None
8181
),
8282
hash=0
83-
)
83+
),
84+
sleep_threshold=60
8485
)
8586

8687
return await utils.parse_messages(client, r)

pyrogram/methods/messages/send_media_group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ async def send_media_group(
176176
multi_media=multi_media,
177177
silent=disable_notification or None,
178178
reply_to_msg_id=reply_to_message_id
179-
)
179+
),
180+
sleep_threshold=60
180181
)
181182

182183
return await utils.parse_messages(

pyrogram/session/session.py

Lines changed: 4 additions & 5 deletions

0 commit comments

Comments
 (0)