mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Handle get_history flood waits
It's likely to get triggered when using iter_history (every ~3k msgs)
This commit is contained in:
parent
52f2a2b17d
commit
67a35f8c7e
@ -16,12 +16,17 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions
|
||||||
|
from pyrogram.api.errors import FloodWait
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GetHistory(BaseClient):
|
class GetHistory(BaseClient):
|
||||||
def get_history(self,
|
def get_history(self,
|
||||||
@ -66,21 +71,28 @@ class GetHistory(BaseClient):
|
|||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
messages = pyrogram.Messages._parse(
|
while True:
|
||||||
self,
|
try:
|
||||||
self.send(
|
messages = pyrogram.Messages._parse(
|
||||||
functions.messages.GetHistory(
|
self,
|
||||||
peer=self.resolve_peer(chat_id),
|
self.send(
|
||||||
offset_id=offset_id,
|
functions.messages.GetHistory(
|
||||||
offset_date=offset_date,
|
peer=self.resolve_peer(chat_id),
|
||||||
add_offset=offset * (-1 if reverse else 1) - (limit if reverse else 0),
|
offset_id=offset_id,
|
||||||
limit=limit,
|
offset_date=offset_date,
|
||||||
max_id=0,
|
add_offset=offset * (-1 if reverse else 1) - (limit if reverse else 0),
|
||||||
min_id=0,
|
limit=limit,
|
||||||
hash=0
|
max_id=0,
|
||||||
|
min_id=0,
|
||||||
|
hash=0
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except FloodWait as e:
|
||||||
)
|
log.warning("Sleeping for {}s".format(e.x))
|
||||||
|
time.sleep(e.x)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
if reverse:
|
if reverse:
|
||||||
messages.messages.reverse()
|
messages.messages.reverse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user