2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Sleep in case of get_dialogs flood waits

This commit is contained in:
Dan 2019-01-04 16:08:05 +01:00
parent c5212dc615
commit 4d1d70082b

View File

@ -16,10 +16,16 @@
# 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
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.api.errors import FloodWait
from ...ext import BaseClient from ...ext import BaseClient
log = logging.getLogger(__name__)
class GetDialogs(BaseClient): class GetDialogs(BaseClient):
def get_dialogs(self, def get_dialogs(self,
@ -29,6 +35,7 @@ class GetDialogs(BaseClient):
"""Use this method to get the user's dialogs """Use this method to get the user's dialogs
You can get up to 100 dialogs at once. You can get up to 100 dialogs at once.
For a more convenient way of getting a user's dialogs see :meth:`iter_dialogs`.
Args: Args:
offset_date (``int``): offset_date (``int``):
@ -50,18 +57,25 @@ class GetDialogs(BaseClient):
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error. :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
""" """
if pinned_only: while True:
r = self.send(functions.messages.GetPinnedDialogs()) try:
else: if pinned_only:
r = self.send( r = self.send(functions.messages.GetPinnedDialogs())
functions.messages.GetDialogs( else:
offset_date=offset_date, r = self.send(
offset_id=0, functions.messages.GetDialogs(
offset_peer=types.InputPeerEmpty(), offset_date=offset_date,
limit=limit, offset_id=0,
hash=0, offset_peer=types.InputPeerEmpty(),
exclude_pinned=True limit=limit,
) hash=0,
) exclude_pinned=True
)
)
except FloodWait as e:
log.warning("Sleeping {}s".format(e.x))
time.sleep(e.x)
else:
break
return pyrogram.Dialogs._parse(self, r) return pyrogram.Dialogs._parse(self, r)