From 9263bdb754bb86a5b78acf3038e9ab0936c6c417 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 12 Sep 2023 23:08:33 +1200 Subject: [PATCH] configuration option to auto-invite matrix users --- d2m/actions/create-space.js | 3 ++- matrix/read-registration.js | 2 ++ registration.example.yaml | 2 ++ types.d.ts | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/d2m/actions/create-space.js b/d2m/actions/create-space.js index 34cf88a..80e49dd 100644 --- a/d2m/actions/create-space.js +++ b/d2m/actions/create-space.js @@ -2,6 +2,7 @@ const assert = require("assert").strict const DiscordTypes = require("discord-api-types/v10") +const reg = require("../../matrix/read-registration") const passthrough = require("../../passthrough") const { discord, sync, db } = passthrough @@ -32,7 +33,7 @@ async function createSpace(guild, kstate) { events_default: 100, // space can only be managed by bridge invite: 0 // any existing member can invite others }, - invite: [], + invite: reg.ooye.invite, topic, creation_content: { type: "m.space" diff --git a/matrix/read-registration.js b/matrix/read-registration.js index 54d77ae..c431907 100644 --- a/matrix/read-registration.js +++ b/matrix/read-registration.js @@ -6,7 +6,9 @@ const yaml = require("js-yaml") /** @ts-ignore @type {import("../types").AppServiceRegistrationConfig} */ const reg = yaml.load(fs.readFileSync("registration.yaml", "utf8")) +reg["ooye"].invite = (reg.ooye.invite || []).filter(mxid => mxid.endsWith(`:${reg.ooye.server_name}`)) // one day I will understand why typescript disagrees with dot notation on this line assert(reg.ooye.max_file_size) assert(reg.ooye.namespace_prefix) assert(reg.ooye.server_name) + module.exports = reg diff --git a/registration.example.yaml b/registration.example.yaml index 802d743..bad42fe 100644 --- a/registration.example.yaml +++ b/registration.example.yaml @@ -18,3 +18,5 @@ ooye: max_file_size: 5000000 server_name: [the part after the colon in your matrix id, like cadence.moe] server_origin: [the full protocol and domain of your actual matrix server's location, with no trailing slash, like https://matrix.cadence.moe] + invite: + # - @cadence:cadence.moe # uncomment this to auto-invite the named user to newly created spaces diff --git a/types.d.ts b/types.d.ts index e3a9909..d4e31ef 100644 --- a/types.d.ts +++ b/types.d.ts @@ -21,6 +21,7 @@ export type AppServiceRegistrationConfig = { max_file_size: number server_name: string server_origin: string + invite: string[] } old_bridge?: { as_token: string