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] 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: