From 4fe90ec5e052d6740c3e68647757a37fc0235a56 Mon Sep 17 00:00:00 2001 From: William Kray Date: Thu, 23 Jun 2022 13:15:06 -0700 Subject: [PATCH] initial commit --- README.md | 2 ++ base-config.yaml | 10 ++++++++++ maubot.yaml | 9 +++++++++ welcome.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 README.md create mode 100644 base-config.yaml create mode 100644 maubot.yaml create mode 100644 welcome.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdebdf3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# welcome bot + diff --git a/base-config.yaml b/base-config.yaml new file mode 100644 index 0000000..d2c269f --- /dev/null +++ b/base-config.yaml @@ -0,0 +1,10 @@ +rooms: + - '!someroom:example.com' + - '!otherroom:example.com' + +# add a room ID here to send a message to when someone joins the above rooms +# (optional) +notification_room: + +message: | + Welcome! Please be sure to read the topic for helpful links and information. diff --git a/maubot.yaml b/maubot.yaml new file mode 100644 index 0000000..adce01f --- /dev/null +++ b/maubot.yaml @@ -0,0 +1,9 @@ +maubot: 0.1.0 +id: org.jobmachine.welcome +version: 0.0.1 +modules: + - welcome +main_class: Greeter +extra_files: + - base-config.yaml +database: false diff --git a/welcome.py b/welcome.py new file mode 100644 index 0000000..8f7f3ba --- /dev/null +++ b/welcome.py @@ -0,0 +1,43 @@ +from typing import Awaitable, Type, Optional, Tuple +import json +import time + +from mautrix.client import Client, InternalEventType, MembershipEventDispatcher, SyncStream +from mautrix.types import (Event, StateEvent, EventID, UserID, EventType, + RoomID, RoomAlias, ReactionEvent, RedactionEvent) +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("message") + helper.copy("notification_room") + + +class Greeter(Plugin): + + async def start(self) -> None: + await super().start() + self.config.load_and_update() + self.client.add_dispatcher(MembershipEventDispatcher) + + @event.on(InternalEventType.JOIN) + async def greet(self, evt: StateEvent) -> None: + if evt.room_id in self.config["rooms"]: + if evt.source & SyncStream.STATE: + return + else: + #await self.client.send_markdown(evt.room_id, self.config["message"], allow_html=True) + await self.client.send_notice(evt.room_id, html=self.config["message"]) + if self.config["notification_room"]: + await self.client.send_markdown(self.config["notification_room"], f"User {evt.sender} joined \ + {evt.room_id}") + + + + @classmethod + def get_config_class(cls) -> Type[BaseProxyConfig]: + return Config