Include message from ping command in pong
This commit is contained in:
parent
9a6e06cc29
commit
6268749a2e
10
echo.py
10
echo.py
|
@ -1,5 +1,6 @@
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue