category subspaces #113
1 changed files with 59 additions and 0 deletions
add script to perform a full space sync
commit
d702e73b06
59
scripts/full-space-sync.js
Normal file
59
scripts/full-space-sync.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue