From b8962780ae6e40944280a47edfade01435af3064 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 15 Sep 2024 00:55:54 +1200 Subject: [PATCH] Fix type errors in scripts and make executable --- scripts/capture-message-update-events.js | 11 ++++++----- scripts/check-migrate.js | 8 ++++---- scripts/migrate-from-old-bridge.js | 20 ++++++++++---------- scripts/save-channel-names-to-db.js | 11 ++++++----- scripts/save-event-types-to-db.js | 5 +++-- scripts/seed.js | 6 +++--- scripts/wal.js | 1 + 7 files changed, 33 insertions(+), 29 deletions(-) mode change 100644 => 100755 scripts/capture-message-update-events.js mode change 100644 => 100755 scripts/check-migrate.js mode change 100644 => 100755 scripts/migrate-from-old-bridge.js mode change 100644 => 100755 scripts/save-channel-names-to-db.js mode change 100644 => 100755 scripts/save-event-types-to-db.js mode change 100644 => 100755 scripts/seed.js mode change 100644 => 100755 scripts/wal.js diff --git a/scripts/capture-message-update-events.js b/scripts/capture-message-update-events.js old mode 100644 new mode 100755 index 671b0625..fb29a5da --- a/scripts/capture-message-update-events.js +++ b/scripts/capture-message-update-events.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // @ts-check // **** @@ -16,16 +17,16 @@ function fieldToPresenceValue(field) { const sqlite = require("better-sqlite3") const HeatSync = require("heatsync") -const config = require("../config") -const passthrough = require("../passthrough") +const {reg} = require("../src/matrix/read-registration") +const passthrough = require("../src/passthrough") const sync = new HeatSync({watchFS: false}) -Object.assign(passthrough, {config, sync}) +Object.assign(passthrough, {sync}) -const DiscordClient = require("../d2m/discord-client") +const DiscordClient = require("../src/d2m/discord-client") -const discord = new DiscordClient(config.discordToken, "no") +const discord = new DiscordClient(reg.ooye.discord_token, "no") passthrough.discord = discord ;(async () => { diff --git a/scripts/check-migrate.js b/scripts/check-migrate.js old mode 100644 new mode 100755 index 308ea872..82f2832a --- a/scripts/check-migrate.js +++ b/scripts/check-migrate.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // @ts-check // Trigger the database migration flow and exit after committing. @@ -5,11 +6,10 @@ const sqlite = require("better-sqlite3") -const config = require("../config") -const passthrough = require("../passthrough") +const passthrough = require("../src/passthrough") const db = new sqlite("db/ooye.db") -const migrate = require("../db/migrate") +const migrate = require("../src/db/migrate") -Object.assign(passthrough, {config, db }) +Object.assign(passthrough, {db}) migrate.migrate(db) diff --git a/scripts/migrate-from-old-bridge.js b/scripts/migrate-from-old-bridge.js old mode 100644 new mode 100755 index e03938de..c47bb052 --- a/scripts/migrate-from-old-bridge.js +++ b/scripts/migrate-from-old-bridge.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // @ts-check const assert = require("assert").strict @@ -6,12 +7,11 @@ const Semaphore = require("@chriscdn/promise-semaphore") const sqlite = require("better-sqlite3") const HeatSync = require("heatsync") -const config = require("../config") -const passthrough = require("../passthrough") +const passthrough = require("../src/passthrough") const sync = new HeatSync({watchFS: false}) -const {reg} = require("../matrix/read-registration") +const {reg} = require("../src/matrix/read-registration") assert(reg.old_bridge) const oldAT = reg.old_bridge.as_token const newAT = reg.as_token @@ -25,19 +25,19 @@ db.exec(`CREATE TABLE IF NOT EXISTS half_shot_migration ( PRIMARY KEY("discord_channel") ) WITHOUT ROWID;`) -Object.assign(passthrough, {config, sync, db}) +Object.assign(passthrough, {sync, db}) -const DiscordClient = require("../d2m/discord-client") -const discord = new DiscordClient(config.discordToken, "half") +const DiscordClient = require("../src/d2m/discord-client") +const discord = new DiscordClient(reg.ooye.discord_token, "half") passthrough.discord = discord -/** @type {import("../d2m/actions/create-space")} */ +/** @type {import("../src/d2m/actions/create-space")} */ const createSpace = sync.require("../d2m/actions/create-space") -/** @type {import("../d2m/actions/create-room")} */ +/** @type {import("../src/d2m/actions/create-room")} */ const createRoom = sync.require("../d2m/actions/create-room") -/** @type {import("../matrix/mreq")} */ +/** @type {import("../src/matrix/mreq")} */ const mreq = sync.require("../matrix/mreq") -/** @type {import("../matrix/api")} */ +/** @type {import("../src/matrix/api")} */ const api = sync.require("../matrix/api") const sema = new Semaphore() diff --git a/scripts/save-channel-names-to-db.js b/scripts/save-channel-names-to-db.js old mode 100644 new mode 100755 index 1e5c5415..7a72949d --- a/scripts/save-channel-names-to-db.js +++ b/scripts/save-channel-names-to-db.js @@ -1,19 +1,20 @@ +#!/usr/bin/env node // @ts-check const sqlite = require("better-sqlite3") const HeatSync = require("heatsync") -const config = require("../config") -const passthrough = require("../passthrough") +const {reg} = require("../src/matrix/read-registration") +const passthrough = require("../src/passthrough") const db = new sqlite("db/ooye.db") const sync = new HeatSync({watchFS: false}) -Object.assign(passthrough, {config, sync, db}) +Object.assign(passthrough, {sync, db}) -const DiscordClient = require("../d2m/discord-client") +const DiscordClient = require("../src/d2m/discord-client") -const discord = new DiscordClient(config.discordToken, "no") +const discord = new DiscordClient(reg.ooye.discord_token, "no") passthrough.discord = discord ;(async () => { diff --git a/scripts/save-event-types-to-db.js b/scripts/save-event-types-to-db.js old mode 100644 new mode 100755 index 290aa4ac..db14e07b --- a/scripts/save-event-types-to-db.js +++ b/scripts/save-event-types-to-db.js @@ -1,16 +1,17 @@ +#!/usr/bin/env node // @ts-check const sqlite = require("better-sqlite3") const HeatSync = require("heatsync") -const passthrough = require("../passthrough") +const passthrough = require("../src/passthrough") const db = new sqlite("db/ooye.db") const sync = new HeatSync({watchFS: false}) Object.assign(passthrough, {sync, db}) -const api = require("../matrix/api") +const api = require("../src/matrix/api") /** @type {{event_id: string, room_id: string, event_type: string}[]} */ // @ts-ignore const rows = db.prepare("SELECT event_id, room_id, event_type FROM event_message INNER JOIN message_channel USING (message_id) INNER JOIN channel_room USING (channel_id)").all() diff --git a/scripts/seed.js b/scripts/seed.js old mode 100644 new mode 100755 index 649f3fc3..991eadc7 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // @ts-check const assert = require("assert").strict @@ -33,14 +34,13 @@ if (fs.existsSync("db")) { fs.rmSync("db", {recursive: true}) } -const config = require("../config") const passthrough = require("../src/passthrough") const db = new sqlite("src/db/ooye.db") const migrate = require("../src/db/migrate") const sync = new HeatSync({watchFS: false}) -Object.assign(passthrough, { sync, config, db }) +Object.assign(passthrough, {sync, db}) const orm = sync.require("../src/db/orm") passthrough.from = orm.from @@ -225,7 +225,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { 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(config.discordToken.split(".")[0], "base64").toString() + 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://") diff --git a/scripts/wal.js b/scripts/wal.js old mode 100644 new mode 100755 index 1ad15d0c..352ac9d3 --- a/scripts/wal.js +++ b/scripts/wal.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node // @ts-check const sqlite = require("better-sqlite3")