4 Commits

Author SHA1 Message Date
Tulir Asokan
0d8d59eb1a Fix incorrect html pong message and bump version to 1.3.1 2019-07-08 18:23:12 +03:00
Tulir Asokan
e5454924dd Bump version to 1.3.0 2019-07-08 10:55:45 +03:00
Tulir Asokan
d325076c9f Don't allow HTML in ping messages 2019-07-08 10:55:07 +03:00
Tulir Asokan
6268749a2e Include message from ping command in pong 2019-07-08 10:49:33 +03:00
2 changed files with 8 additions and 4 deletions

10
echo.py
View File

@@ -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)
text_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 {text_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> {html_message} "
f"{pretty_diff} to arrive)")
content["pong"] = {
"ms": diff,

View File

@@ -1,6 +1,6 @@
maubot: 0.1.0
id: xyz.maubot.echo
version: 1.2.0
version: 1.3.1
license: MIT
modules:
- echo