Skip to content

Commit 436c48d

Browse files
committed
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
1 parent b753e48 commit 436c48d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

pyrogram/client/ext/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import logging
2020
from base64 import b64decode, b64encode
2121
from struct import pack
22-
from weakref import proxy
2322

2423
from pyrogram.client import types as pyrogram_types
2524
from ...api import types, functions
@@ -624,7 +623,7 @@ def parse_messages(
624623
views=message.views,
625624
via_bot=parse_user(users.get(message.via_bot_id, None)),
626625
outgoing=message.out,
627-
client=proxy(client),
626+
client=client,
628627
reply_markup=reply_markup
629628
)
630629

@@ -739,7 +738,7 @@ def parse_messages(
739738
migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
740739
group_chat_created=group_chat_created,
741740
channel_chat_created=channel_chat_created,
742-
client=proxy(client)
741+
client=client
743742
# TODO: supergroup_chat_created
744743
)
745744

@@ -753,7 +752,7 @@ def parse_messages(
753752
except MessageIdsEmpty:
754753
pass
755754
else:
756-
m = pyrogram_types.Message(message_id=message.id, client=proxy(client), empty=True)
755+
m = pyrogram_types.Message(message_id=message.id, client=client, empty=True)
757756

758757
parsed_messages.append(m)
759758

pyrogram/client/methods/messages/send_message.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def send_message(self,
6767
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
6868
"""
6969
style = self.html if parse_mode.lower() == "html" else self.markdown
70+
message, entities = style.parse(text).values()
7071

7172
r = self.send(
7273
functions.messages.SendMessage(
@@ -76,16 +77,20 @@ def send_message(self,
7677
reply_to_msg_id=reply_to_message_id,
7778
random_id=self.rnd_id(),
7879
reply_markup=reply_markup.write() if reply_markup else None,
79-
**style.parse(text)
80+
message=message,
81+
entities=entities
8082
)
8183
)
8284

8385
if isinstance(r, types.UpdateShortSentMessage):
8486
return pyrogram_types.Message(
8587
message_id=r.id,
88+
chat=pyrogram_types.Chat(id=list(self.resolve_peer(chat_id).__dict__.values())[0], type="private"),
89+
text=message,
8690
date=r.date,
8791
outgoing=r.out,
88-
entities=utils.parse_entities(r.entities, {}) or None
92+
entities=entities,
93+
client=self
8994
)
9095

9196
for i in r.updates:

0 commit comments

Comments
 (0)