From 734c9a583875caa34b459bb1adbf3a860ae993d3 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 25 Sep 2024 13:37:54 +1200 Subject: [PATCH 1/2] Remove hardcoded cadence.moe --- scripts/seed.js | 5 +++-- src/matrix/read-registration.js | 11 +++++++---- src/web/pug/guild.pug | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/seed.js b/scripts/seed.js index f20afb7..3603595 100755 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -105,7 +105,8 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { const serverNameResponse = await prompt({ type: "input", name: "server_name", - message: "Homeserver name" + message: "Homeserver name", + validate: serverName => !!serverName.match(/[a-z][a-z.]+[a-z]/) }) console.log("What is the URL of your homeserver?") @@ -176,7 +177,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { message: "Client secret" }) - const template = getTemplateRegistration() + const template = getTemplateRegistration(serverNameResponse.server_name) reg = { ...template, url: bridgeOriginResponse.bridge_origin, diff --git a/src/matrix/read-registration.js b/src/matrix/read-registration.js index 8438387..fec434f 100644 --- a/src/matrix/read-registration.js +++ b/src/matrix/read-registration.js @@ -24,8 +24,11 @@ function writeRegistration(reg) { fs.writeFileSync(registrationFilePath, JSON.stringify(reg, null, 2)) } -/** @returns {import("../types").InitialAppServiceRegistrationConfig} reg */ -function getTemplateRegistration() { +/** + * @param {string} serverName + * @returns {import("../types").InitialAppServiceRegistrationConfig} reg + */ +function getTemplateRegistration(serverName) { return { id: "ooye", as_token: crypto.randomBytes(32).toString("hex"), @@ -33,11 +36,11 @@ function getTemplateRegistration() { namespaces: { users: [{ exclusive: true, - regex: "@_ooye_.*:cadence.moe" + regex: `@_ooye_.*:${serverName}` }], aliases: [{ exclusive: true, - regex: "#_ooye_.*:cadence.moe" + regex: `#_ooye_.*:${serverName}` }] }, protocols: [ diff --git a/src/web/pug/guild.pug b/src/web/pug/guild.pug index b5449a4..f92bf75 100644 --- a/src/web/pug/guild.pug +++ b/src/web/pug/guild.pug @@ -136,7 +136,7 @@ block body form.d-flex.ai-center.g8 label.s-label.fl-grow1(for="autocreate") | Create new Matrix rooms automatically - p.s-description If you want, OOYE can automatically create new Matrix rooms and link them when a new Discord channel is spoken in. + p.s-description If you want, OOYE can automatically create new Matrix rooms and link them when an unlinked Discord channel is spoken in. - let value = select("guild_active", "autocreate", {guild_id}).pluck().get() input(type="hidden" name="guild_id" value=guild_id) input.s-toggle-switch.order-last#autocreate(name="autocreate" type="checkbox" hx-post="/api/autocreate" hx-indicator="#autocreate-loading" hx-disabled-elt="this" checked=value) From d6de57f0c36bd7c01255f642bd099e7e56c2881c Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 26 Sep 2024 02:16:50 +1200 Subject: [PATCH 2/2] Factor out namespace_prefix --- src/matrix/read-registration.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/matrix/read-registration.js b/src/matrix/read-registration.js index fec434f..9fb0535 100644 --- a/src/matrix/read-registration.js +++ b/src/matrix/read-registration.js @@ -29,6 +29,7 @@ function writeRegistration(reg) { * @returns {import("../types").InitialAppServiceRegistrationConfig} reg */ function getTemplateRegistration(serverName) { + const namespace_prefix = "_ooye_" return { id: "ooye", as_token: crypto.randomBytes(32).toString("hex"), @@ -36,21 +37,21 @@ function getTemplateRegistration(serverName) { namespaces: { users: [{ exclusive: true, - regex: `@_ooye_.*:${serverName}` + regex: `@${namespace_prefix}.*:${serverName}` }], aliases: [{ exclusive: true, - regex: `#_ooye_.*:${serverName}` + regex: `#${namespace_prefix}.*:${serverName}` }] }, protocols: [ "discord" ], - sender_localpart: "_ooye_bot", + sender_localpart: `${namespace_prefix}bot`, rate_limited: false, socket: 6693, ooye: { - namespace_prefix: "_ooye_", + namespace_prefix, max_file_size: 5000000, content_length_workaround: false, include_user_id_in_mxid: false,