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
This commit is contained in:
Dan 2018-11-20 16:52:59 +01:00
parent b753e48732
commit 436c48d1c2
2 changed files with 10 additions and 6 deletions

View File

@ -19,7 +19,6 @@
import logging import logging
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
from struct import pack from struct import pack
from weakref import proxy
from pyrogram.client import types as pyrogram_types from pyrogram.client import types as pyrogram_types
from ...api import types, functions from ...api import types, functions
@ -624,7 +623,7 @@ def parse_messages(
views=message.views, views=message.views,
via_bot=parse_user(users.get(message.via_bot_id, None)), via_bot=parse_user(users.get(message.via_bot_id, None)),
outgoing=message.out, outgoing=message.out,
client=proxy(client), client=client,
reply_markup=reply_markup 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, migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
group_chat_created=group_chat_created, group_chat_created=group_chat_created,
channel_chat_created=channel_chat_created, channel_chat_created=channel_chat_created,
client=proxy(client) client=client
# TODO: supergroup_chat_created # TODO: supergroup_chat_created
) )
@ -753,7 +752,7 @@ def parse_messages(
except MessageIdsEmpty: except MessageIdsEmpty:
pass pass
else: 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) parsed_messages.append(m)

View File

@ -67,6 +67,7 @@ class SendMessage(BaseClient):
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error. :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
message, entities = style.parse(text).values()
r = self.send( r = self.send(
functions.messages.SendMessage( functions.messages.SendMessage(
@ -76,16 +77,20 @@ class SendMessage(BaseClient):
reply_to_msg_id=reply_to_message_id, reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(), random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None, reply_markup=reply_markup.write() if reply_markup else None,
**style.parse(text) message=message,
entities=entities
) )
) )
if isinstance(r, types.UpdateShortSentMessage): if isinstance(r, types.UpdateShortSentMessage):
return pyrogram_types.Message( return pyrogram_types.Message(
message_id=r.id, 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, date=r.date,
outgoing=r.out, outgoing=r.out,
entities=utils.parse_entities(r.entities, {}) or None entities=entities,
client=self
) )
for i in r.updates: for i in r.updates: