From 89daf095000741d0f72c06b58d1ed2502ef96d29 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 29 Jan 2018 14:20:16 +0100 Subject: [PATCH 01/17] Switch back to port 443 --- pyrogram/connection/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index aa958a7a..d912da74 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -33,7 +33,7 @@ class Connection: } def __init__(self, ipv4: str, proxy: type, mode: int = 1): - self.address = (ipv4, 80) + self.address = (ipv4, 443) self.proxy = proxy self.mode = self.MODES.get(mode, TCPAbridged) self.lock = threading.Lock() From bdfba51410d11779c1d9a807ea749f0890f16ff7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 30 Jan 2018 13:35:23 +0100 Subject: [PATCH 02/17] Revert "Switch back to port 443" This reverts commit 89daf09 --- pyrogram/connection/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index d912da74..aa958a7a 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -33,7 +33,7 @@ class Connection: } def __init__(self, ipv4: str, proxy: type, mode: int = 1): - self.address = (ipv4, 443) + self.address = (ipv4, 80) self.proxy = proxy self.mode = self.MODES.get(mode, TCPAbridged) self.lock = threading.Lock() From 19f861964e03d8e52df12df54846353188225c8d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 30 Jan 2018 13:45:47 +0100 Subject: [PATCH 03/17] Update to v0.5.0 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 78942791..09545a6c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Thu, 1 Feb 2018 12:47:41 +0300 Subject: [PATCH 04/17] add PHONE_NUMBER_BANNED --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 810c503b..5e30172b 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -42,4 +42,5 @@ CDN_METHOD_INVALID The method can't be used on CDN DCs VOLUME_LOC_NOT_FOUND The volume location can't be found FILE_ID_INVALID The file id is invalid LOCATION_INVALID The file location is invalid -CHAT_ADMIN_REQUIRED The method requires admin privileges \ No newline at end of file +CHAT_ADMIN_REQUIRED The method requires admin privileges +PHONE_NUMBER_BANNED The phone number is banned \ No newline at end of file From df5666e2a00c422b72ccd4eab58a1d442962419a Mon Sep 17 00:00:00 2001 From: RussFP <1pyxa1@gmail.com> Date: Thu, 1 Feb 2018 12:49:43 +0300 Subject: [PATCH 05/17] add PhoneNumberBanned exception to 'def authorize' --- pyrogram/client/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 5fd75cc0..ea1ea89e 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -37,7 +37,7 @@ from pyrogram.api.errors import ( PhoneNumberUnoccupied, PhoneCodeInvalid, PhoneCodeHashEmpty, PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, - ChatAdminRequired, FirstnameInvalid + ChatAdminRequired, FirstnameInvalid, PhoneNumberBanned ) from pyrogram.api.types import ( User, Chat, Channel, @@ -283,6 +283,9 @@ class Client: except FloodWait as e: print(e.MESSAGE.format(x=e.x)) time.sleep(e.x) + except PhoneNumberBanned as e: + log.error(e, exc_info=True) + raise except Exception as e: log.error(e, exc_info=True) else: From 214d3fe0bcbfbc43f332d4034eb4d2595026b7d6 Mon Sep 17 00:00:00 2001 From: RussFP <1pyxa1@gmail.com> Date: Thu, 1 Feb 2018 12:57:06 +0300 Subject: [PATCH 06/17] small fix --- compiler/error/source/400_BAD_REQUEST.tsv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 5e30172b..0b92aba5 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -43,4 +43,4 @@ VOLUME_LOC_NOT_FOUND The volume location can't be found FILE_ID_INVALID The file id is invalid LOCATION_INVALID The file location is invalid CHAT_ADMIN_REQUIRED The method requires admin privileges -PHONE_NUMBER_BANNED The phone number is banned \ No newline at end of file +PHONE_NUMBER_BANNED The phone number is banned From 00a02472f57b5ce898469d058afc4d40c07df2d8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 1 Feb 2018 13:41:23 +0100 Subject: [PATCH 07/17] Make PhoneNumberBanned error looking more gentle --- pyrogram/client/client.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index ea1ea89e..b6180a9c 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -274,7 +274,7 @@ class Client: ) ) break - except PhoneNumberInvalid as e: + except (PhoneNumberInvalid, PhoneNumberBanned) as e: if phone_number_invalid_raises: raise else: @@ -283,9 +283,6 @@ class Client: except FloodWait as e: print(e.MESSAGE.format(x=e.x)) time.sleep(e.x) - except PhoneNumberBanned as e: - log.error(e, exc_info=True) - raise except Exception as e: log.error(e, exc_info=True) else: From 455e444d8b683d97909ded2f5e24fb79d73c0a29 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 1 Feb 2018 15:34:56 +0100 Subject: [PATCH 08/17] Patch Layer 75 --- compiler/api/source/main_api.tl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 08607100..212867e5 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -733,7 +733,7 @@ payments.savedInfo#fb8fe43c flags:# has_saved_credentials:flags.1?true saved_inf inputPaymentCredentialsSaved#c10eb2cf id:string tmp_password:bytes = InputPaymentCredentials; inputPaymentCredentials#3417d728 flags:# save:flags.0?true data:DataJSON = InputPaymentCredentials; inputPaymentCredentialsApplePay#aa1c39f payment_data:DataJSON = InputPaymentCredentials; -inputPaymentCredentialsAndroidPay#795667a6 payment_token:DataJSON = InputPaymentCredentials; +inputPaymentCredentialsAndroidPay#ca05d50e payment_token:DataJSON google_transaction_id:string = InputPaymentCredentials; account.tmpPassword#db64fd34 tmp_password:bytes valid_until:int = account.TmpPassword; @@ -841,8 +841,8 @@ auth.resendCode#3ef1a9bf phone_number:string phone_code_hash:string = auth.SentC auth.cancelCode#1f040578 phone_number:string phone_code_hash:string = Bool; auth.dropTempAuthKeys#8e48a188 except_auth_keys:Vector = Bool; -account.registerDevice#637ea878 token_type:int token:string = Bool; -account.unregisterDevice#65c55b40 token_type:int token:string = Bool; +account.registerDevice#1389cc token_type:int token:string app_sandbox:Bool other_uids:Vector = Bool; +account.unregisterDevice#3076c4bf token_type:int token:string other_uids:Vector = Bool; account.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool; account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings; account.resetNotifySettings#db7e1747 = Bool; @@ -910,7 +910,6 @@ messages.editChatPhoto#ca4c79d8 chat_id:int photo:InputChatPhoto = Updates; messages.addChatUser#f9a0aa09 chat_id:int user_id:InputUser fwd_limit:int = Updates; messages.deleteChatUser#e0611f16 chat_id:int user_id:InputUser = Updates; messages.createChat#9cb126e users:Vector title:string = Updates; -messages.forwardMessage#33963bf9 peer:InputPeer id:int random_id:long = Updates; messages.getDhConfig#26cf8950 version:int random_length:int = messages.DhConfig; messages.requestEncryption#f64daf43 user_id:InputUser random_id:int g_a:bytes = EncryptedChat; messages.acceptEncryption#3dbc0415 peer:InputEncryptedChat g_b:bytes key_fingerprint:long = EncryptedChat; @@ -923,6 +922,7 @@ messages.sendEncryptedService#32d439a4 peer:InputEncryptedChat random_id:long da messages.receivedQueue#55a5bb66 max_qts:int = Vector; messages.reportEncryptedSpam#4b0c8c0f peer:InputEncryptedChat = Bool; messages.readMessageContents#36a73f77 id:Vector = messages.AffectedMessages; +messages.getStickers#ae22e045 emoticon:string hash:string = messages.Stickers; messages.getAllStickers#1c9618b1 hash:int = messages.AllStickers; messages.getWebPagePreview#8b68b0cc flags:# message:string entities:flags.3?Vector = MessageMedia; messages.exportChatInvite#7d885289 chat_id:int = ExportedChatInvite; @@ -1034,7 +1034,7 @@ channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector = channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite; channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; channels.toggleInvites#49609307 channel:InputChannel enabled:Bool = Updates; -channels.exportMessageLink#c846d22d channel:InputChannel id:int = ExportedMessageLink; +channels.exportMessageLink#ceb77163 channel:InputChannel id:int grouped:Bool = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.updatePinnedMessage#a72ded52 flags:# silent:flags.0?true channel:InputChannel id:int = Updates; channels.getAdminedPublicChannels#8d8d82d7 = messages.Chats; From eb36a8f261e4056146770968c1d81e4c8a450d98 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 2 Feb 2018 19:00:43 +0100 Subject: [PATCH 09/17] Add InputMedia class --- pyrogram/__init__.py | 1 + pyrogram/client/input_media.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 pyrogram/client/input_media.py diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 09545a6c..767a4cab 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,3 +29,4 @@ from .api.errors import Error from .client import ChatAction from .client import Client from .client import ParseMode +from .client.input_media import InputMedia diff --git a/pyrogram/client/input_media.py b/pyrogram/client/input_media.py new file mode 100644 index 00000000..e61ccc15 --- /dev/null +++ b/pyrogram/client/input_media.py @@ -0,0 +1,24 @@ +class InputMedia: + class Photo: + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = ""): + self.media = media + self.caption = caption + self.parse_mode = parse_mode + + class Video: + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + width: int = 0, + height: int = 0, + duration: int = 0): + self.media = media + self.caption = caption + self.parse_mode = parse_mode + self.width = width + self.height = height + self.duration = duration From 995167c5347fd8ef1534b296bcf111f804ef654d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Feb 2018 12:25:49 +0100 Subject: [PATCH 10/17] Add docstrings --- pyrogram/client/input_media.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pyrogram/client/input_media.py b/pyrogram/client/input_media.py index e61ccc15..d7612121 100644 --- a/pyrogram/client/input_media.py +++ b/pyrogram/client/input_media.py @@ -1,5 +1,21 @@ class InputMedia: class Photo: + """This object represents a photo to be sent inside an album. + + Args: + media (:obj:`str`): + File to send. + Pass a file path as string to send a photo that exists on your local machine. + + caption (:obj:`str`): + Caption of the photo to be sent, 0-200 characters + + parse_mode (:obj:`str`): + Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps + to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + """ + def __init__(self, media: str, caption: str = "", @@ -9,6 +25,22 @@ class InputMedia: self.parse_mode = parse_mode class Video: + """This object represents a video to be sent inside an album. + + Args: + media (:obj:`str`): + File to send. + Pass a file path as string to send a video that exists on your local machine. + + caption (:obj:`str`): + Caption of the video to be sent, 0-200 characters + + parse_mode (:obj:`str`): + Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps + to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + """ + def __init__(self, media: str, caption: str = "", From 63531dd1dd3f5e6ebdd38c81c6d4574ad01b55d3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 5 Feb 2018 01:50:32 +0100 Subject: [PATCH 11/17] Fix regex pattern not matching single quotes --- pyrogram/client/style/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/style/html.py b/pyrogram/client/style/html.py index d1e876a1..41127011 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -31,7 +31,7 @@ from . import utils class HTML: - HTML_RE = re.compile(r"<(\w+)(?: href=\"(.*)\")?>(.*)") + HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])(.*)\2)?>(.*)") MENTION_RE = re.compile(r"tg://user\?id=(\d+)") def __init__(self, peers_by_id): From cfb36351f9c6193f5d8dd64654f1ee4b981a7c1e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 6 Feb 2018 15:49:43 +0100 Subject: [PATCH 12/17] Add InputMedia docs --- docs/source/pyrogram/InputMedia.rst | 6 ++++++ docs/source/pyrogram/index.rst | 1 + 2 files changed, 7 insertions(+) create mode 100644 docs/source/pyrogram/InputMedia.rst diff --git a/docs/source/pyrogram/InputMedia.rst b/docs/source/pyrogram/InputMedia.rst new file mode 100644 index 00000000..c637bdc0 --- /dev/null +++ b/docs/source/pyrogram/InputMedia.rst @@ -0,0 +1,6 @@ +InputMedia +========== + +.. autoclass:: pyrogram.InputMedia + :members: + :undoc-members: diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index e484bd5e..160766eb 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -11,6 +11,7 @@ the same parameters as well, thus offering a familiar look to Bot developers. Client ChatAction ParseMode + InputMedia Error .. _Telegram Bot API: https://core.telegram.org/bots/api#available-methods From 2b127ee6f8e2bcf4ac2a64733ac832ed6e1ba6a5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 7 Feb 2018 01:12:52 +0100 Subject: [PATCH 13/17] Fix inputSingleMedia --- compiler/api/source/main_api.tl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 212867e5..ca2ea52f 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -813,7 +813,7 @@ recentMeUrlStickerSet#bc0a57dc url:string set:StickerSetCovered = RecentMeUrl; help.recentMeUrls#e0310d7 urls:Vector chats:Vector users:Vector = help.RecentMeUrls; -inputSingleMedia#31bc3d25 media:InputMedia flags:# random_id:long message:string entities:flags.0?Vector = InputSingleMedia; +inputSingleMedia#1cc6e91f flags:# media:InputMedia random_id:long message:string entities:flags.0?Vector = InputSingleMedia; ---functions--- From a358b1f26b25afc8ebc39939622d694b66895100 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 7 Feb 2018 03:05:02 +0100 Subject: [PATCH 14/17] Add send_media_group method --- pyrogram/client/client.py | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index b6180a9c..4da6bc88 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -48,6 +48,7 @@ from pyrogram.api.types import ( ) from pyrogram.crypto import CTR from pyrogram.session import Auth, Session +from .input_media import InputMedia from .style import Markdown, HTML log = logging.getLogger(__name__) @@ -1941,3 +1942,79 @@ class Client: ) else: return False + + def send_media_group(self, + chat_id: int or str, + media: list, + disable_notification: bool = None, + reply_to_message_id: int = None): + multi_media = [] + + for i in media: + if isinstance(i, InputMedia.Photo): + style = self.html if i.parse_mode.lower() == "html" else self.markdown + media = self.save_file(i.media) + + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedPhoto( + file=media + ) + ) + ) + + single_media = types.InputSingleMedia( + media=types.InputMediaPhoto( + id=types.InputPhoto( + id=media.photo.id, + access_hash=media.photo.access_hash + ) + ), + random_id=self.rnd_id(), + **style.parse(i.caption) + ) + + multi_media.append(single_media) + elif isinstance(i, InputMedia.Video): + style = self.html if i.parse_mode.lower() == "html" else self.markdown + media = self.save_file(i.media) + + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + file=media, + mime_type=mimetypes.types_map[".mp4"], + attributes=[ + types.DocumentAttributeVideo( + duration=i.duration, + w=i.width, + h=i.height + ) + ] + ) + ) + ) + + single_media = types.InputSingleMedia( + media=types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ), + random_id=self.rnd_id(), + **style.parse(i.caption) + ) + + multi_media.append(single_media) + + return self.send( + functions.messages.SendMultiMedia( + peer=self.resolve_peer(chat_id), + multi_media=multi_media, + silent=disable_notification or None, + reply_to_msg_id=reply_to_message_id + ) + ) From 0d359a4b1ac61418b43d35c6389e2bc96ce6bcbe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 7 Feb 2018 03:13:21 +0100 Subject: [PATCH 15/17] Add docstrings --- pyrogram/client/client.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 4da6bc88..9ae4b549 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1948,6 +1948,26 @@ class Client: media: list, disable_notification: bool = None, reply_to_message_id: int = None): + """Use this method to send a group of photos or videos as an album. + On success, an Update containing the sent Messages is returned. + + Args: + chat_id (:obj:`int` | :obj:`str`): + Unique identifier for the target chat or username of the target channel/supergroup + (in the format @username). For your personal cloud storage (Saved Messages) you can + simply use "me" or "self". + + media (:obj:`list`): + A list containing either :obj:`pyrogram.InputMedia.Photo` or :obj:`pyrogram.InputMedia.Video` objects + describing photos and videos to be sent, must include 2–10 items. + + disable_notification (:obj:`bool`, optional): + Sends the message silently. + Users will receive a notification with no sound. + + reply_to_message_id (:obj:`int`, optional): + If the message is a reply, ID of the original message. + """ multi_media = [] for i in media: From 6783d7b16f5eec217b5ba4c94c19771e9e771b69 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 7 Feb 2018 03:24:50 +0100 Subject: [PATCH 16/17] Fix reply_to_message_id parameter for send_message --- pyrogram/client/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9ae4b549..2b9318a1 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -605,7 +605,7 @@ class Client: parse_mode: str = "", disable_web_page_preview: bool = None, disable_notification: bool = None, - reply_to_msg_id: int = None): + reply_to_message_id: int = None): """Use this method to send text messages. Args: @@ -629,7 +629,7 @@ class Client: Sends the message silently. Users will receive a notification with no sound. - reply_to_msg_id (:obj:`bool`, optional): + reply_to_message_id (:obj:`bool`, optional): If the message is a reply, ID of the original message. Returns: @@ -645,7 +645,7 @@ class Client: peer=self.resolve_peer(chat_id), no_webpage=disable_web_page_preview or None, silent=disable_notification or None, - reply_to_msg_id=reply_to_msg_id, + reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), **style.parse(text) ) From 403a37692c0b09f409b9979b877136f7a110b337 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 7 Feb 2018 03:35:34 +0100 Subject: [PATCH 17/17] Handle GetDialogs FloodWait errors --- pyrogram/client/client.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2b9318a1..d5a69e73 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -495,12 +495,17 @@ class Client: log.info("Dialogs count: {}".format(len(peers))) while len(dialogs.dialogs) == self.DIALOGS_AT_ONCE: - dialogs = self.send( - functions.messages.GetDialogs( - offset_date, 0, types.InputPeerEmpty(), - self.DIALOGS_AT_ONCE, True + try: + dialogs = self.send( + functions.messages.GetDialogs( + offset_date, 0, types.InputPeerEmpty(), + self.DIALOGS_AT_ONCE, True + ) ) - ) + except FloodWait as e: + log.info("Get dialogs flood wait: {}".format(e.x)) + time.sleep(e.x) + continue offset_date = parse_dialogs(dialogs) log.info("Dialogs count: {}".format(len(peers)))