Transformation to Compliance-bot

This commit is contained in:
2024-04-26 13:41:32 +02:00
parent a6d3e6cbea
commit 08226566eb
4 changed files with 15 additions and 16 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.mbp

View File

@@ -1,4 +1,4 @@
rooms: excluded_rooms:
- '!someroom:example.com' - '!someroom:example.com'
- '!otherroom:example.com' - '!otherroom:example.com'
@@ -17,5 +17,6 @@ notification_message: |
# matrix.to link (rendered as a "pill" in element clients) # matrix.to link (rendered as a "pill" in element clients)
# html formatting is supported # html formatting is supported
message: | message: |
Welcome {user}! Please be sure to read the topic for helpful links and information. Welcome {user}!<br />
Use <a href="https://google.com">Google</a> for all other queries ;) Please notice that this room is now archived with ArchiBot.<br />
If you have any questions about archivation, please contact Compliance department.

View File

@@ -1,9 +1,9 @@
maubot: 0.1.0 maubot: 0.1.0
id: org.jobmachine.welcome id: net.cqre.compliance-bot
version: 0.0.4 version: 0.0.1
license: MIT license: MIT
modules: modules:
- welcome - compliance-bot
main_class: Greeter main_class: Greeter
extra_files: extra_files:
- base-config.yaml - base-config.yaml

View File

@@ -9,17 +9,14 @@ from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent from maubot import Plugin, MessageEvent
from maubot.handlers import command, event from maubot.handlers import command, event
class Config(BaseProxyConfig): class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None: def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("rooms") helper.copy("excluded_rooms") # Changed "rooms" to "excluded_rooms"
helper.copy("message") helper.copy("message")
helper.copy("notification_room") helper.copy("notification_room")
helper.copy("notification_message") helper.copy("notification_message")
class Greeter(Plugin): class Greeter(Plugin):
async def start(self) -> None: async def start(self) -> None:
await super().start() await super().start()
self.config.load_and_update() self.config.load_and_update()
@@ -27,23 +24,23 @@ class Greeter(Plugin):
@event.on(InternalEventType.JOIN) @event.on(InternalEventType.JOIN)
async def greet(self, evt: StateEvent) -> None: async def greet(self, evt: StateEvent) -> None:
if evt.room_id in self.config["rooms"]: # Exclude rooms listed in "excluded_rooms"
if evt.room_id not in self.config["excluded_rooms"]:
if evt.source & SyncStream.STATE: if evt.source & SyncStream.STATE:
return return
else: else:
nick = self.client.parse_user_id(evt.sender)[0] nick = self.client.parse_user_id(evt.sender)[0]
pill = '<a href="https://matrix.to/#/{mxid}">{nick}</a>'.format(mxid=evt.sender, nick=nick) pill = '<a href="https://matrix.to/#/{mxid}">{nick}</a>'.format(mxid=evt.sender, nick=nick)
msg = self.config["message"].format(user=pill) msg = self.config["message"].format(user=pill)
await self.client.send_notice(evt.room_id, html=msg) await self.client.send_notice(evt.room_id, html=msg)
if self.config["notification_room"]: if self.config["notification_room"]:
roomnamestate = await self.client.get_state_event(evt.room_id, 'm.room.name') roomnamestate = await self.client.get_state_event(evt.room_id, 'm.room.name')
roomname = roomnamestate['name'] roomname = roomnamestate['name'] if 'name' in roomnamestate else 'Unnamed Room'
notification_message = self.config['notification_message'].format(user=evt.sender, notification_message = self.config['notification_message'].format(user=evt.sender,
room=roomname) room=roomname)
await self.client.send_notice(self.config["notification_room"], html=notification_message) await self.client.send_notice(self.config["notification_room"], html=notification_message)
@classmethod @classmethod
def get_config_class(cls) -> Type[BaseProxyConfig]: def get_config_class(cls) -> Type[BaseProxyConfig]:
return Config return Config