Commit 6268749a authored by Tulir Asokan's avatar Tulir Asokan

Include message from ping command in pong

parent 9a6e06cc
from typing import Optional
from time import time
from html import escape
from mautrix.types import TextMessageEventContent, MessageType, Format
......@@ -34,14 +35,17 @@ class EchoBot(Plugin):
f"{cls.plural(minutes, 'minute')} and {cls.plural(seconds, 'second')}")
@command.new("ping", help="Ping")
async def ping_handler(self, evt: MessageEvent) -> None:
@command.argument("message", pass_raw=True, required=False)
async def ping_handler(self, evt: MessageEvent, message: str = "") -> None:
diff = int(time() * 1000) - evt.timestamp
pretty_diff = self.prettify_diff(diff)
message = f'"{message[:20]}" took' if message else "took"
html_message = f'"{escape(message[:20])}" took' if message else "took"
content = TextMessageEventContent(
msgtype=MessageType.NOTICE, format=Format.HTML,
body=f"{evt.sender}: Pong! (ping took {pretty_diff} to arrive)",
body=f"{evt.sender}: Pong! (ping {message} {pretty_diff} to arrive)",
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> took "
f"(<a href='https://matrix.to/#/{evt.room_id}/{evt.event_id}'>ping</a> {message} "
f"{pretty_diff} to arrive)")
content["pong"] = {
"ms": diff,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment