Use RelatesTo and RelationType classes

This commit is contained in:
Tulir Asokan 2020-03-01 14:06:07 +02:00
parent 25aa06e1ff
commit 0e5b7bc2db

19
echo.py
View file

@ -2,7 +2,7 @@ from typing import Optional
from time import time from time import time
from html import escape from html import escape
from mautrix.types import TextMessageEventContent, MessageType, Format from mautrix.types import TextMessageEventContent, MessageType, Format, RelatesTo, RelationType
from maubot import Plugin, MessageEvent from maubot import Plugin, MessageEvent
from maubot.handlers import command from maubot.handlers import command
@ -46,18 +46,19 @@ class EchoBot(Plugin):
body=f"{evt.sender}: Pong! (ping {text_message} {pretty_diff} to arrive)", body=f"{evt.sender}: Pong! (ping {text_message} {pretty_diff} to arrive)",
formatted_body=f"<a href='https://matrix.to/#/{evt.sender}'>{evt.sender}</a>: Pong! " formatted_body=f"<a href='https://matrix.to/#/{evt.sender}'>{evt.sender}</a>: Pong! "
f"(<a href='https://matrix.to/#/{evt.room_id}/{evt.event_id}'>ping</a> {html_message} " f"(<a href='https://matrix.to/#/{evt.room_id}/{evt.event_id}'>ping</a> {html_message} "
f"{pretty_diff} to arrive)") f"{pretty_diff} to arrive)",
relates_to=RelatesTo(
rel_type=RelationType("xyz.maubot.pong"),
event_id=evt.event_id,
))
pong_from = evt.sender.split(":", 1)[1]
content.relates_to["from"] = pong_from
content.relates_to["ms"] = diff
content["pong"] = { content["pong"] = {
"ms": diff, "ms": diff,
"from": evt.sender.split(":", 1)[1], "from": pong_from,
"ping": evt.event_id, "ping": evt.event_id,
} }
content["m.relates_to"] = {
"rel_type": "xyz.maubot.pong",
"event_id": evt.event_id,
"from": evt.sender.split(":", 1)[1],
"ms": diff,
}
await evt.respond(content) await evt.respond(content)
@command.new("echo", help="Repeat a message") @command.new("echo", help="Repeat a message")