Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
546e5eee21 | ||
|
|
0e5b7bc2db | ||
|
|
25aa06e1ff | ||
|
|
4ade107370 | ||
|
|
e9b4cd47a2 | ||
|
|
4d3f4f1556 | ||
|
|
0d8d59eb1a | ||
|
|
e5454924dd | ||
|
|
d325076c9f | ||
|
|
6268749a2e | ||
|
|
9a6e06cc29 | ||
|
|
37df8c89d6 |
27
.gitlab-ci.yml
Normal file
27
.gitlab-ci.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
image: dock.mau.dev/maubot/maubot
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
|
||||||
|
variables:
|
||||||
|
PYTHONPATH: /opt/maubot
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
except:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- python3 -m maubot.cli build -o xyz.maubot.$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA.mbp
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- "*.mbp"
|
||||||
|
|
||||||
|
build tags:
|
||||||
|
stage: build
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- python3 -m maubot.cli build -o xyz.maubot.$CI_PROJECT_NAME-$CI_COMMIT_TAG.mbp
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- "*.mbp"
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2019 Tulir Asokan
|
Copyright (c) 2020 Tulir Asokan
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|||||||
29
echo.py
29
echo.py
@@ -1,7 +1,8 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from time import time
|
from time import time
|
||||||
|
from html import escape
|
||||||
|
|
||||||
from mautrix.types import TextMessageEventContent, MessageType
|
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
|
||||||
@@ -34,17 +35,31 @@ class EchoBot(Plugin):
|
|||||||
f"{cls.plural(minutes, 'minute')} and {cls.plural(seconds, 'second')}")
|
f"{cls.plural(minutes, 'minute')} and {cls.plural(seconds, 'second')}")
|
||||||
|
|
||||||
@command.new("ping", help="Ping")
|
@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
|
diff = int(time() * 1000) - evt.timestamp
|
||||||
content = TextMessageEventContent(msgtype=MessageType.NOTICE,
|
pretty_diff = self.prettify_diff(diff)
|
||||||
body="Pong! (ping took "
|
text_message = f'"{message[:20]}" took' if message else "took"
|
||||||
f"{self.prettify_diff(diff)} to arrive)")
|
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 {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> {html_message} "
|
||||||
|
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,
|
||||||
}
|
}
|
||||||
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.4.0
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- echo
|
- echo
|
||||||
|
|||||||
Reference in New Issue
Block a user