1
0
Fork 0

Fix type errors in scripts and make executable

This commit is contained in:
Cadence Ember 2024-09-15 00:55:54 +12:00
parent 256196cc54
commit b8962780ae
7 changed files with 33 additions and 29 deletions

11
scripts/capture-message-update-events.js Normal file → Executable file
View file

@ -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 () => {

8
scripts/check-migrate.js Normal file → Executable file
View file

@ -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)

20
scripts/migrate-from-old-bridge.js Normal file → Executable file
View file

@ -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()

11
scripts/save-channel-names-to-db.js Normal file → Executable file
View file

@ -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 () => {

5
scripts/save-event-types-to-db.js Normal file → Executable file
View file

@ -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()

6
scripts/seed.js Normal file → Executable file
View file

@ -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://")

1
scripts/wal.js Normal file → Executable file
View file

@ -1,3 +1,4 @@
#!/usr/bin/env node
// @ts-check
const sqlite = require("better-sqlite3")