Rich reply fallbacks in send_reply

This commit is contained in:
deadcade 2022-08-29 13:25:05 +02:00
parent 6a27b369af
commit a592871047
1 changed files with 4 additions and 0 deletions

View File

@ -191,6 +191,10 @@ async def send_reply(room_id, original_event, text):
unformatted = html.unescape(unformatted)
# \n doesn't work in HTML, replace it with <br>
formatted = formatted.replace("\n", "<br>")
originalbody = original_event.formatted_body if original_event.formatted_body else original_event.body
formatted = f"<mx-reply><blockquote><a href=\"https://matrix.to/#/{room_id}/{original_event.event_id}\">In reply to</a> <a href=\"https://matrix.to/#/{original_event.sender}\">{original_event.sender}</a><br/>{originalbody}</blockquote></mx-reply>{formatted}"
quotedbody = original_event.body.replace('\n', '\n> ')
unformatted = f"> <{original_event.sender}> {quotedbody}\n\n{unformatted}"
return await client.room_send(room_id=room_id, message_type="m.room.message", content={"msgtype": "m.text", "body": unformatted + " (SelfBot)", "format": "org.matrix.custom.html", "formatted_body": formatted + (f" (<a href=\"{settings['source_url']}\">SelfBot</a>)" if settings["source_url"] else " (SelfBot)"), "m.relates_to": {"m.in_reply_to": {"event_id": original_event.event_id}}}, ignore_unverified_devices=True)
# Commands definition