From 40d7ed2b8eb113aafc13a040d7f1f1b3a55de253 Mon Sep 17 00:00:00 2001 From: Aleksandr Pyatnitsin Date: Wed, 14 Nov 2018 23:21:19 +0300 Subject: [PATCH 1/4] fix RawUpdateHandler --- pyrogram/client/dispatcher/dispatcher.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index a61e8077..3ab704fc 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -129,7 +129,7 @@ class Dispatcher: if parser is None: continue - update, handler_type = parser(update, users, chats) + parsed_update, handler_type = parser(update, users, chats) for group in self.groups.values(): for handler in group: @@ -138,8 +138,8 @@ class Dispatcher: if isinstance(handler, RawUpdateHandler): args = (update, users, chats) elif isinstance(handler, handler_type): - if handler.check(update): - args = (update,) + if handler.check(parsed_update): + args = (parsed_update,) if args is None: continue From 08776619a78035da4ed5a82d6b191c159df4bab6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:03:26 +0100 Subject: [PATCH 2/4] Change callback_data type to bytes for request_callback_answer Fixes #161 --- pyrogram/client/methods/bots/request_callback_answer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index c2c7e312..470ad15a 100644 --- a/pyrogram/client/methods/bots/request_callback_answer.py +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -24,7 +24,7 @@ class RequestCallbackAnswer(BaseClient): def request_callback_answer(self, chat_id: int or str, message_id: int, - callback_data: str): + callback_data: bytes): """Use this method to request a callback answer from bots. This is the equivalent of clicking an inline button containing callback data. @@ -37,7 +37,7 @@ class RequestCallbackAnswer(BaseClient): message_id (``int``): The message id the inline keyboard is attached on. - callback_data (``str``): + callback_data (``bytes``): Callback data associated with the inline button you want to get the answer from. Returns: @@ -52,7 +52,7 @@ class RequestCallbackAnswer(BaseClient): functions.messages.GetBotCallbackAnswer( peer=self.resolve_peer(chat_id), msg_id=message_id, - data=callback_data.encode() + data=callback_data ), retries=0, timeout=10 From b753e48732616614b99dd3bada8ad2bbb6cba3c1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:04:03 +0100 Subject: [PATCH 3/4] Remove unnecessary check --- pyrogram/client/types/messages_and_media/message.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 404ad39d..3715ba1a 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -579,10 +579,7 @@ class Message(Object): ``TimeoutError``: If, after clicking an inline button, the bot fails to answer within 10 seconds """ if isinstance(self.reply_markup, ReplyKeyboardMarkup): - if quote is None: - quote = self.chat.type != "private" - - return self.reply(x, quote=quote) + return self.reply(x) elif isinstance(self.reply_markup, InlineKeyboardMarkup): if isinstance(x, int) and y is None: try: From 436c48d1c201731b279c3d2c1e0c66a4c0bbc467 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Nov 2018 16:52:59 +0100 Subject: [PATCH 4/4] Allow Bots to edit and delete own messages w/ Message bound methods. This is some sort of a workaround because the server doesn't send full info about text messages originated by bots. Fixes #162 --- pyrogram/client/ext/utils.py | 7 +++---- pyrogram/client/methods/messages/send_message.py | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a543e6b5..15605bea 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -19,7 +19,6 @@ import logging from base64 import b64decode, b64encode from struct import pack -from weakref import proxy from pyrogram.client import types as pyrogram_types from ...api import types, functions @@ -624,7 +623,7 @@ def parse_messages( views=message.views, via_bot=parse_user(users.get(message.via_bot_id, None)), outgoing=message.out, - client=proxy(client), + client=client, reply_markup=reply_markup ) @@ -739,7 +738,7 @@ def parse_messages( migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None, group_chat_created=group_chat_created, channel_chat_created=channel_chat_created, - client=proxy(client) + client=client # TODO: supergroup_chat_created ) @@ -753,7 +752,7 @@ def parse_messages( except MessageIdsEmpty: pass else: - m = pyrogram_types.Message(message_id=message.id, client=proxy(client), empty=True) + m = pyrogram_types.Message(message_id=message.id, client=client, empty=True) parsed_messages.append(m) diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index 2ad4b8e4..78ce27e5 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -67,6 +67,7 @@ class SendMessage(BaseClient): :class:`Error ` in case of a Telegram RPC error. """ style = self.html if parse_mode.lower() == "html" else self.markdown + message, entities = style.parse(text).values() r = self.send( functions.messages.SendMessage( @@ -76,16 +77,20 @@ class SendMessage(BaseClient): reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), reply_markup=reply_markup.write() if reply_markup else None, - **style.parse(text) + message=message, + entities=entities ) ) if isinstance(r, types.UpdateShortSentMessage): return pyrogram_types.Message( message_id=r.id, + chat=pyrogram_types.Chat(id=list(self.resolve_peer(chat_id).__dict__.values())[0], type="private"), + text=message, date=r.date, outgoing=r.out, - entities=utils.parse_entities(r.entities, {}) or None + entities=entities, + client=self ) for i in r.updates: