include welcome module with multi-room message-mapping support
This commit is contained in:
@@ -29,3 +29,31 @@ admins:
|
||||
invitees:
|
||||
- "@mybot:server.tld"
|
||||
- "@secondaryadmin:server.tld"
|
||||
|
||||
# auto-greet users in rooms with these messages
|
||||
# map greeting messages to a room
|
||||
# you can use {user} to reference the joining user in this message using a
|
||||
# matrix.to link (rendered as a "pill" in element clients)
|
||||
# html formatting is supported
|
||||
greetings:
|
||||
generic: |
|
||||
Welcome {user}! Please be sure to read the topic for helpful links and information.
|
||||
Use <a href="https://google.com">Google</a> for all other queries ;)
|
||||
encrypted: |
|
||||
welcome {user}, this is an encrypted room, so you may not be able to see messages previously sent here. don't be
|
||||
alarmed.
|
||||
|
||||
# which of the above greetings should be used in which rooms? use the exact name of each greeting
|
||||
# you've assigned, e.g. 'generic' or 'encrypted'
|
||||
greeting_rooms:
|
||||
'!someroomid:server.tld': generic
|
||||
'!someotherroom:server.tld': generic
|
||||
'!myencryptedroomid:server.tld': encrypted
|
||||
|
||||
# add a room ID here to send a message to when someone joins the above rooms
|
||||
# (optional)
|
||||
notification_room:
|
||||
|
||||
# message to send to the notification room when someone joins one of the above rooms:
|
||||
join_notification_message: |
|
||||
User <code>{user}</code> has joined <code>{room}</code>.
|
||||
|
||||
+28
-3
@@ -5,9 +5,10 @@ import json
|
||||
import time
|
||||
import re
|
||||
|
||||
from mautrix.client import Client, InternalEventType, MembershipEventDispatcher
|
||||
from mautrix.client import Client, InternalEventType, MembershipEventDispatcher, SyncStream
|
||||
from mautrix.types import (Event, StateEvent, EventID, UserID, FileInfo, EventType,
|
||||
MediaMessageEventContent, ReactionEvent, RedactionEvent)
|
||||
MediaMessageEventContent, ReactionEvent, RedactionEvent, RoomID,
|
||||
RoomAlias)
|
||||
from mautrix.errors import MNotFound
|
||||
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
|
||||
from maubot import Plugin, MessageEvent
|
||||
@@ -28,6 +29,10 @@ class Config(BaseProxyConfig):
|
||||
helper.copy("kick_threshold_days")
|
||||
helper.copy("encrypt")
|
||||
helper.copy("invitees")
|
||||
helper.copy("notification_room")
|
||||
helper.copy("join_notification_message")
|
||||
helper.copy_dict("greeting_rooms")
|
||||
helper.copy_dict("greetings")
|
||||
|
||||
|
||||
class CommunityBot(Plugin):
|
||||
@@ -102,9 +107,29 @@ class CommunityBot(Plugin):
|
||||
return report
|
||||
|
||||
@event.on(InternalEventType.JOIN)
|
||||
async def passive_sync(self, evt:StateEvent) -> None:
|
||||
async def newjoin(self, evt:StateEvent) -> None:
|
||||
# passive sync of tracking db
|
||||
if evt.room_id == self.config['parent_room']:
|
||||
await self.do_sync()
|
||||
self.log.debug(self.config["greeting_rooms"])
|
||||
# greeting activities
|
||||
room_id = str(evt.room_id)
|
||||
if room_id in self.config["greeting_rooms"]:
|
||||
greeting_map = self.config['greetings']
|
||||
greeting_name = self.config['greeting_rooms'][room_id]
|
||||
if evt.source & SyncStream.STATE:
|
||||
return
|
||||
else:
|
||||
nick = self.client.parse_user_id(evt.sender)[0]
|
||||
pill = '<a href="https://matrix.to/#/{mxid}">{nick}</a>'.format(mxid=evt.sender, nick=nick)
|
||||
greeting = greeting_map[greeting_name].format(user=pill)
|
||||
await self.client.send_notice(evt.room_id, html=greeting)
|
||||
if self.config["notification_room"]:
|
||||
roomnamestate = await self.client.get_state_event(evt.room_id, 'm.room.name')
|
||||
roomname = roomnamestate['name']
|
||||
notification_message = self.config['join_notification_message'].format(user=evt.sender,
|
||||
room=roomname)
|
||||
await self.client.send_notice(self.config["notification_room"], html=notification_message)
|
||||
|
||||
@event.on(EventType.ROOM_MESSAGE)
|
||||
async def update_message_timestamp(self, evt: MessageEvent) -> None:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
maubot: 0.1.0
|
||||
id: org.jobmachine.communitybot
|
||||
version: 0.0.1
|
||||
version: 0.0.2
|
||||
license: MIT
|
||||
modules:
|
||||
- community
|
||||
|
||||
Reference in New Issue
Block a user