From a63d173a9a2cdc03c129e5f8bb4e0ed57b290d3d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 25 Nov 2024 16:30:10 +1300 Subject: [PATCH] Remove redundant/invalid checks from setup --- scripts/setup.js | 13 +------------ src/m2d/converters/utils.js | 4 +--- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/setup.js b/scripts/setup.js index f1817b7..a8b068b 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -230,7 +230,6 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { // Done with user prompts, reg is now guaranteed to be valid const api = require("../src/matrix/api") const file = require("../src/matrix/file") - const utils = require("../src/m2d/converters/utils") const DiscordClient = require("../src/d2m/discord-client") const discord = new DiscordClient(reg.ooye.discord_token, "no") passthrough.discord = discord @@ -267,21 +266,11 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { const mxid = `@${reg.sender_localpart}:${reg.ooye.server_name}` - // ensure registration is correctly set... - assert(reg.sender_localpart.startsWith(reg.ooye.namespace_prefix), "appservice's localpart must be in the namespace it controls") - assert(utils.eventSenderIsFromDiscord(mxid), "appservice's mxid must be in the namespace it controls") - assert(reg.ooye.server_origin.match(/^https?:\/\//), "server origin must start with http or https") - assert.notEqual(reg.ooye.server_origin.slice(-1), "/", "server origin must not end in slash") - const botID = Buffer.from(reg.ooye.discord_token.split(".")[0], "base64").toString() - assert(botID.match(/^[0-9]{10,}$/), "discord token must follow the correct format") - assert.match(reg.url, /^https?:/, "url must start with http:// or https://") - - console.log("✅ Configuration looks good...") - // database ddl... await migrate.migrate(db) // add initial rows to database, like adding the bot to sim... + const botID = Buffer.from(reg.ooye.discord_token.split(".")[0], "base64").toString() db.prepare("INSERT OR IGNORE INTO sim (user_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run(botID, reg.sender_localpart.slice(reg.ooye.namespace_prefix.length), reg.sender_localpart, mxid) console.log("✅ Database is ready...") diff --git a/src/m2d/converters/utils.js b/src/m2d/converters/utils.js index c538627..17cb0fd 100644 --- a/src/m2d/converters/utils.js +++ b/src/m2d/converters/utils.js @@ -30,9 +30,7 @@ const NEWLINE_ELEMENTS = BLOCK_ELEMENTS.concat(["BR"]) */ function eventSenderIsFromDiscord(sender) { // If it's from a user in the bridge's namespace, then it originated from discord - // This includes messages sent by the appservice's bot user, because that is what's used for webhooks - // TODO: It would be nice if bridge system messages wouldn't trigger this check and could be bridged from matrix to discord, while webhook reflections would remain ignored... - // TODO that only applies to the above todo: But you'd have to watch out for the /icon command, where the bridge bot would set the room avatar, and that shouldn't be reflected into the room a second time. + // This could include messages sent by the appservice's bot user, because that is what's used for webhooks if (userRegex.some(x => sender.match(x))) { return true }