File tree Expand file tree Collapse file tree 1 file changed +26
-14
lines changed
pyrogram/client/methods/messages Expand file tree Collapse file tree 1 file changed +26
-14
lines changed Original file line number Diff line number Diff line change 1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import logging
20+ import time
1921from typing import Union
2022
2123import pyrogram
2224from pyrogram .api import functions
25+ from pyrogram .api .errors import FloodWait
2326from ...ext import BaseClient
2427
28+ log = logging .getLogger (__name__ )
29+
2530
2631class GetHistory (BaseClient ):
2732 def get_history (self ,
@@ -66,21 +71,28 @@ def get_history(self,
6671 :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
6772 """
6873
69- messages = pyrogram .Messages ._parse (
70- self ,
71- self .send (
72- functions .messages .GetHistory (
73- peer = self .resolve_peer (chat_id ),
74- offset_id = offset_id ,
75- offset_date = offset_date ,
76- add_offset = offset * (- 1 if reverse else 1 ) - (limit if reverse else 0 ),
77- limit = limit ,
78- max_id = 0 ,
79- min_id = 0 ,
80- hash = 0
74+ while True :
75+ try :
76+ messages = pyrogram .Messages ._parse (
77+ self ,
78+ self .send (
79+ functions .messages .GetHistory (
80+ peer = self .resolve_peer (chat_id ),
81+ offset_id = offset_id ,
82+ offset_date = offset_date ,
83+ add_offset = offset * (- 1 if reverse else 1 ) - (limit if reverse else 0 ),
84+ limit = limit ,
85+ max_id = 0 ,
86+ min_id = 0 ,
87+ hash = 0
88+ )
89+ )
8190 )
82- )
83- )
91+ except FloodWait as e :
92+ log .warning ("Sleeping for {}s" .format (e .x ))
93+ time .sleep (e .x )
94+ else :
95+ break
8496
8597 if reverse :
8698 messages .messages .reverse ()
You can’t perform that action at this time.
0 commit comments