2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Wait in case of flood errors in get_messages

This commit is contained in:
Dan 2019-01-04 14:38:08 +01:00
parent fe89974523
commit 7e3513f8ee

View File

@ -16,12 +16,17 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import logging
import time
from typing import Union, Iterable
import pyrogram
from pyrogram.api import functions, types
from pyrogram.api.errors import FloodWait
from ...ext import BaseClient
log = logging.getLogger(__name__)
class GetMessages(BaseClient):
def get_messages(self,
@ -78,6 +83,15 @@ class GetMessages(BaseClient):
else:
rpc = functions.messages.GetMessages(id=ids)
messages = pyrogram.Messages._parse(self, self.send(rpc), replies)
while True:
try:
r = self.send(rpc)
except FloodWait as e:
log.warning("Sleeping for {}s".format(e.x))
time.sleep(e.x)
else:
break
messages = pyrogram.Messages._parse(self, r, replies=replies)
return messages if is_iterable else messages.messages[0]