From 96af2ebcf26d153a5219bbd18af57c3bf95f178c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 3 Nov 2018 17:04:04 +0100 Subject: [PATCH 1/8] Fix getattr failing for ChannelForbidden objects --- pyrogram/client/ext/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a2f1c3db..696174a7 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -215,7 +215,7 @@ def parse_channel_chat(channel: types.Channel) -> pyrogram_types.Chat: title=channel.title, username=getattr(channel, "username", None), photo=parse_chat_photo(getattr(channel, "photo", None)), - restriction_reason=getattr(channel, "restriction_reason") + restriction_reason=getattr(channel, "restriction_reason", None) ) From 30c0086fde9533734f007fc7187b0fa9bf86d6fe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 3 Nov 2018 22:01:26 +0100 Subject: [PATCH 2/8] Fix missing total_count for ChatMembers in channels/supergroups --- pyrogram/client/ext/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 696174a7..74b373eb 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -973,6 +973,7 @@ def parse_chat_members(members: types.channels.ChannelParticipants or types.mess parsed_members = [] if isinstance(members, types.channels.ChannelParticipants): + count = members.count members = members.participants for member in members: @@ -1031,7 +1032,7 @@ def parse_chat_members(members: types.channels.ChannelParticipants or types.mess parsed_members.append(chat_member) return pyrogram_types.ChatMembers( - total_count=members.count, + total_count=count, chat_members=parsed_members ) else: From af937152a108aa187a04c1b10d35e1bb8383130c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 09:36:21 +0100 Subject: [PATCH 3/8] Don't decode inline buttons callback data Clients are able to set any value as plain bytes, this means UTF-8 decoding could fail. --- pyrogram/client/types/bots/inline_keyboard_button.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index 0f4779a9..ce93d96b 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -31,7 +31,7 @@ class InlineKeyboardButton(Object): text (``str``): Label text on the button. - callback_data (``str``, *optional*): + callback_data (``bytes``, *optional*): Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes. url (``str``, *optional*): @@ -85,7 +85,7 @@ class InlineKeyboardButton(Object): if isinstance(b, KeyboardButtonCallback): return InlineKeyboardButton( text=b.text, - callback_data=b.data.decode() + callback_data=b.data ) if isinstance(b, KeyboardButtonSwitchInline): From 46e19c395cd7f7136d0d386857b5535a3f9d2f5d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 11:36:10 +0100 Subject: [PATCH 4/8] Don't encode callback data when sending inline buttons --- pyrogram/client/types/bots/inline_keyboard_button.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index ce93d96b..3d6c7b6b 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -59,7 +59,7 @@ class InlineKeyboardButton(Object): def __init__( self, text: str, - callback_data: str = None, + callback_data: bytes = None, url: str = None, switch_inline_query: str = None, switch_inline_query_current_chat: str = None, @@ -102,7 +102,7 @@ class InlineKeyboardButton(Object): def write(self): if self.callback_data: - return KeyboardButtonCallback(self.text, self.callback_data.encode()) + return KeyboardButtonCallback(self.text, self.callback_data) if self.url: return KeyboardButtonUrl(self.text, self.url) From 966926d38310363ffd6c16cc4b1bc8e770e61460 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 16:53:23 +0100 Subject: [PATCH 5/8] Remove unneeded FloodWait check --- pyrogram/client/ext/utils.py | 38 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 74b373eb..f573c2e9 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -17,12 +17,10 @@ # along with Pyrogram. If not, see . import logging -import time from base64 import b64decode, b64encode from struct import pack from weakref import proxy -from pyrogram.api.errors import FloodWait from pyrogram.client import types as pyrogram_types from ...api import types, functions from ...api.errors import StickersetInvalid @@ -635,19 +633,11 @@ def parse_messages( m.caption.init(m._client, m.caption_entities or []) if message.reply_to_msg_id and replies: - while True: - try: - m.reply_to_message = client.get_messages( - m.chat.id, - reply_to_message_ids=message.id, - replies=replies - 1 - ) - except FloodWait as e: - log.warning("get_messages flood: waiting {} seconds".format(e.x)) - time.sleep(e.x) - continue - else: - break + m.reply_to_message = client.get_messages( + m.chat.id, + reply_to_message_ids=message.id, + replies=replies - 1 + ) elif isinstance(message, types.MessageService): action = message.action @@ -748,19 +738,11 @@ def parse_messages( ) if isinstance(action, types.MessageActionPinMessage): - while True: - try: - m.pinned_message = client.get_messages( - m.chat.id, - reply_to_message_ids=message.id, - replies=0 - ) - except FloodWait as e: - log.warning("get_messages flood: waiting {} seconds".format(e.x)) - time.sleep(e.x) - continue - else: - break + m.pinned_message = client.get_messages( + m.chat.id, + reply_to_message_ids=message.id, + replies=0 + ) else: m = pyrogram_types.Message(message_id=message.id, client=proxy(client)) From b1e35ef9be137298d9ff68cbb187e9e3befa6bbe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 17:24:43 +0100 Subject: [PATCH 6/8] Add MESSAGE_IDS_EMPTY rpc error --- 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 3ef57b83..382e521e 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -67,4 +67,5 @@ USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side USER_NOT_PARTICIPANT The user is not a member of this chat -CHANNEL_PRIVATE The channel/supergroup is not accessible \ No newline at end of file +CHANNEL_PRIVATE The channel/supergroup is not accessible +MESSAGE_IDS_EMPTY The requested message doesn't exist \ No newline at end of file From ff7ee4678a290e39af5de61a99ebe1a2aea11589 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 17:25:39 +0100 Subject: [PATCH 7/8] Catch possible MESSAGE_IDS_EMPTY errors --- pyrogram/client/ext/utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index f573c2e9..bc908165 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -23,7 +23,7 @@ from weakref import proxy from pyrogram.client import types as pyrogram_types from ...api import types, functions -from ...api.errors import StickersetInvalid +from ...api.errors import StickersetInvalid, MessageIdsEmpty log = logging.getLogger(__name__) @@ -633,11 +633,14 @@ def parse_messages( m.caption.init(m._client, m.caption_entities or []) if message.reply_to_msg_id and replies: - m.reply_to_message = client.get_messages( - m.chat.id, - reply_to_message_ids=message.id, - replies=replies - 1 - ) + try: + m.reply_to_message = client.get_messages( + m.chat.id, + reply_to_message_ids=message.id, + replies=replies - 1 + ) + except MessageIdsEmpty: + m.reply_to_message = None elif isinstance(message, types.MessageService): action = message.action From e3a93b339c7cb59b19250373220a80ded436c28c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 4 Nov 2018 17:50:51 +0100 Subject: [PATCH 8/8] Update to v0.9.1 --- docs/source/start/Installation.rst | 2 +- pyrogram/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index e7b2eb3d..37fedbdf 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -82,7 +82,7 @@ If no error shows up you are good to go. >>> import pyrogram >>> pyrogram.__version__ - '0.9.0' + '0.9.1' .. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto .. _develop: http://github.com/pyrogram/pyrogram diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2f5981e0..4f9866e0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès