Allow specifying a threshold to handle flood waits

This commit is contained in:
Lonami Exo 2017-10-08 16:15:30 +02:00
parent 83677fc927
commit 15e90dcb69
2 changed files with 12 additions and 4 deletions

View File

@ -534,11 +534,17 @@ class TelegramBareClient:
'[ERROR] Telegram is having some internal issues', e '[ERROR] Telegram is having some internal issues', e
) )
except FloodWaitError: except FloodWaitError as e:
if e.seconds > self.session.flood_sleep_threshold | 0:
sender.disconnect() sender.disconnect()
self.disconnect() self.disconnect()
raise raise
self._logger.debug(
'Sleep of %d seconds below threshold, sleeping' % e.seconds
)
sleep(e.seconds)
# Some really basic functionality # Some really basic functionality
def is_user_authorized(self): def is_user_authorized(self):

View File

@ -37,6 +37,7 @@ class Session:
self.lang_pack = session.lang_pack self.lang_pack = session.lang_pack
self.report_errors = session.report_errors self.report_errors = session.report_errors
self.save_entities = session.save_entities self.save_entities = session.save_entities
self.flood_sleep_threshold = session.flood_sleep_threshold
else: # str / None else: # str / None
self.session_user_id = session_user_id self.session_user_id = session_user_id
@ -50,6 +51,7 @@ class Session:
self.lang_pack = '' self.lang_pack = ''
self.report_errors = True self.report_errors = True
self.save_entities = True self.save_entities = True
self.flood_sleep_threshold = 60
# Cross-thread safety # Cross-thread safety
self._seq_no_lock = Lock() self._seq_no_lock = Lock()