category subspaces #113

Open
mschae wants to merge 9 commits from mschae/out-of-your-element:category-subspaces into main
Showing only changes of commit d702e73b06 - Show all commits

add script to perform a full space sync

mschae23 2026-11-21 13:58:30 +01:00
Signed by untrusted user: mschae
GPG key ID: A87721D300DE88AB

View file

@ -0,0 +1,59 @@
#!/usr/bin/env node
// @ts-check
const {guild: guild_id} = require("minimist")(process.argv.slice(2), {string: ["guild"]})
if (!guild_id) {
console.error("Usage: ./scripts/full-space-sync.js --guild=<guild ID here>")
process.exit(1)
}
const sqlite = require("better-sqlite3")
const HeatSync = require("heatsync")
const {reg} = require("../src/matrix/read-registration")
const passthrough = require("../src/passthrough")
const sync = new HeatSync({watchFS: false})
const db = new sqlite("ooye.db")
Object.assign(passthrough, {sync, db})
const DiscordTypes = require("discord-api-types/v10")
const DiscordClient = require("../src/d2m/discord-client")
const discord = new DiscordClient(reg.ooye.discord_token, "half")
passthrough.discord = discord
const {as} = require("../src/matrix/appservice")
passthrough.as = as
const orm = sync.require("../src/db/orm")
passthrough.from = orm.from
passthrough.select = orm.select
/** @type {import("../src/d2m/event-dispatcher")}*/
const eventDispatcher = sync.require("../src/d2m/event-dispatcher")
/** @type {import("../src/d2m/actions/create-space")}) */
const createSpace = sync.require("../src/d2m/actions/create-space")
;(async () => {
await discord.cloud.connect()
console.log("Connected, waiting for data about requested guild...")
discord.cloud.on("event", event)
})()
/**
* @param {import("cloudstorm").IGatewayMessage} event
*/
async function event(event) {
if (event.t !== "GUILD_CREATE") return
if (event.d.id !== guild_id) return
try {
await createSpace.syncSpaceFully(guild_id)
} catch (e) {
console.error(e)
process.exit(1) // won't exit automatically on thrown error due to living discord connection, so manual exit is necessary
}
}