From 08226566ebbc3345b9808683aa870cad288f8477 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Fri, 26 Apr 2024 13:41:32 +0200 Subject: [PATCH] Transformation to Compliance-bot --- .gitignore | 1 + base-config.yaml | 7 ++++--- maubot.yaml | 6 +++--- welcome.py | 17 +++++++---------- 4 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a60ef10 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.mbp diff --git a/base-config.yaml b/base-config.yaml index c8057a8..8a3eab7 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -1,4 +1,4 @@ -rooms: +excluded_rooms: - '!someroom:example.com' - '!otherroom:example.com' @@ -17,5 +17,6 @@ notification_message: | # matrix.to link (rendered as a "pill" in element clients) # html formatting is supported message: | - Welcome {user}! Please be sure to read the topic for helpful links and information. - Use Google for all other queries ;) + Welcome {user}!
+ Please notice that this room is now archived with ArchiBot.
+ If you have any questions about archivation, please contact Compliance department. diff --git a/maubot.yaml b/maubot.yaml index 500ed67..aee554f 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,9 +1,9 @@ maubot: 0.1.0 -id: org.jobmachine.welcome -version: 0.0.4 +id: net.cqre.compliance-bot +version: 0.0.1 license: MIT modules: - - welcome + - compliance-bot main_class: Greeter extra_files: - base-config.yaml diff --git a/welcome.py b/welcome.py index c83ec95..936d71e 100644 --- a/welcome.py +++ b/welcome.py @@ -9,17 +9,14 @@ from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from maubot import Plugin, MessageEvent from maubot.handlers import command, event - class Config(BaseProxyConfig): def do_update(self, helper: ConfigUpdateHelper) -> None: - helper.copy("rooms") + helper.copy("excluded_rooms") # Changed "rooms" to "excluded_rooms" helper.copy("message") helper.copy("notification_room") helper.copy("notification_message") - class Greeter(Plugin): - async def start(self) -> None: await super().start() self.config.load_and_update() @@ -27,23 +24,23 @@ class Greeter(Plugin): @event.on(InternalEventType.JOIN) 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: return else: nick = self.client.parse_user_id(evt.sender)[0] pill = '{nick}'.format(mxid=evt.sender, nick=nick) - msg = self.config["message"].format(user=pill) - await self.client.send_notice(evt.room_id, html=msg) + msg = self.config["message"].format(user=pill) + await self.client.send_notice(evt.room_id, html=msg) + if self.config["notification_room"]: 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, room=roomname) await self.client.send_notice(self.config["notification_room"], html=notification_message) - - @classmethod def get_config_class(cls) -> Type[BaseProxyConfig]: return Config