Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a6e06cc29 | ||
|
|
37df8c89d6 |
14
echo.py
14
echo.py
@@ -1,7 +1,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from mautrix.types import TextMessageEventContent, MessageType
|
from mautrix.types import TextMessageEventContent, MessageType, Format
|
||||||
|
|
||||||
from maubot import Plugin, MessageEvent
|
from maubot import Plugin, MessageEvent
|
||||||
from maubot.handlers import command
|
from maubot.handlers import command
|
||||||
@@ -36,15 +36,19 @@ class EchoBot(Plugin):
|
|||||||
@command.new("ping", help="Ping")
|
@command.new("ping", help="Ping")
|
||||||
async def ping_handler(self, evt: MessageEvent) -> None:
|
async def ping_handler(self, evt: MessageEvent) -> None:
|
||||||
diff = int(time() * 1000) - evt.timestamp
|
diff = int(time() * 1000) - evt.timestamp
|
||||||
content = TextMessageEventContent(msgtype=MessageType.NOTICE,
|
pretty_diff = self.prettify_diff(diff)
|
||||||
body="Pong! (ping took "
|
content = TextMessageEventContent(
|
||||||
f"{self.prettify_diff(diff)} to arrive)")
|
msgtype=MessageType.NOTICE, format=Format.HTML,
|
||||||
|
body=f"{evt.sender}: Pong! (ping took {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"{pretty_diff} to arrive)")
|
||||||
content["pong"] = {
|
content["pong"] = {
|
||||||
"ms": diff,
|
"ms": diff,
|
||||||
"from": evt.sender.split(":", 1)[1],
|
"from": evt.sender.split(":", 1)[1],
|
||||||
"ping": evt.event_id,
|
"ping": evt.event_id,
|
||||||
}
|
}
|
||||||
await evt.reply(content)
|
await evt.respond(content)
|
||||||
|
|
||||||
@command.new("echo", help="Repeat a message")
|
@command.new("echo", help="Repeat a message")
|
||||||
@command.argument("message", pass_raw=True)
|
@command.argument("message", pass_raw=True)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: xyz.maubot.echo
|
id: xyz.maubot.echo
|
||||||
version: 1.1.1
|
version: 1.2.0
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- echo
|
- echo
|
||||||
|
|||||||
Reference in New Issue
Block a user