Replace send_message_super with markdown flag in send_message

This commit is contained in:
Tulir Asokan
2018-03-03 21:02:01 +02:00
parent 0f706d511a
commit 172e472221
3 changed files with 12 additions and 10 deletions
+2 -2
View File
@@ -122,14 +122,14 @@ class Bot(AbstractUser):
async def handle_command(self, message): async def handle_command(self, message):
def reply(reply_text): def reply(reply_text):
return self.client.send_message_super(message.to_id, reply_text) return self.client.send_message(message.to_id, reply_text, markdown=True)
text = message.message text = message.message
portal = po.Portal.get_by_entity(message.to_id) portal = po.Portal.get_by_entity(message.to_id)
if text == "/portal" or text == f"/portal@{self.username}": if text == "/portal" or text == f"/portal@{self.username}":
await self.handle_command_portal(portal, reply) await self.handle_command_portal(portal, reply)
elif text.startswith("/invite ") or text.startswith(f"/invite@{self.username} "): elif text.startswith("/invite ") or text.startswith(f"/invite@{self.username} "):
await self.handle_command_invite(portal, reply, mxid=text[text.index(" "):]) await self.handle_command_invite(portal, reply, mxid=text[text.index(" ") + 1:])
def handle_service_message(self, message): def handle_service_message(self, message):
to_id = message.to_id to_id = message.to_id
+4 -4
View File
@@ -523,8 +523,8 @@ class Portal:
async def leave_matrix(self, user, source, event_id): async def leave_matrix(self, user, source, event_id):
if not user.logged_in: if not user.logged_in:
response = await self.bot.client.send_message_super( response = await self.bot.client.send_message(
self.peer, f"__{user.displayname} left the room.__") self.peer, f"__{user.displayname} left the room.__", markdown=True)
space = self.tgid if self.peer_type == "channel" else self.bot.tgid space = self.tgid if self.peer_type == "channel" else self.bot.tgid
self.is_duplicate(response, (event_id, space)) self.is_duplicate(response, (event_id, space))
return return
@@ -554,8 +554,8 @@ class Portal:
async def join_matrix(self, user, event_id): async def join_matrix(self, user, event_id):
if not user.logged_in: if not user.logged_in:
response = await self.bot.client.send_message_super( response = await self.bot.client.send_message(
self.peer, f"__{user.displayname} joined the room.__") self.peer, f"__{user.displayname} joined the room.__", markdown=True)
space = self.tgid if self.peer_type == "channel" else self.bot.tgid space = self.tgid if self.peer_type == "channel" else self.bot.tgid
self.is_duplicate(response, (event_id, space)) self.is_duplicate(response, (event_id, space))
return return
+6 -4
View File
@@ -19,15 +19,17 @@ from io import BytesIO
from telethon import TelegramClient from telethon import TelegramClient
from telethon.tl.functions.messages import SendMessageRequest, SendMediaRequest from telethon.tl.functions.messages import SendMessageRequest, SendMediaRequest
from telethon.tl.types import * from telethon.tl.types import *
from telethon.extensions.markdown import parse as parse_md
class MautrixTelegramClient(TelegramClient): class MautrixTelegramClient(TelegramClient):
def send_message_super(self, *args, **kwargs): async def send_message(self, entity, message, reply_to=None, entities=None, markdown=False,
return super().send_message(*args, **kwargs) link_preview=True):
async def send_message(self, entity, message, reply_to=None, entities=None, link_preview=True):
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
if markdown:
message, entities = parse_md(message)
request = SendMessageRequest( request = SendMessageRequest(
peer=entity, peer=entity,
message=message, message=message,