Backfill: Create new rooms when needed
This updates the backfill script to attempt to create rooms for unbridged rooms, rather than bombing out that the room isn't already bridged. Co-authored-by: Cadence Ember <cadence@disroot.org> Reviewed-on: #75 Co-authored-by: Bea <beanie@theargo.space> Co-committed-by: Bea <beanie@theargo.space>
This commit is contained in:
parent
f5ee130463
commit
ada3933d9c
1 changed files with 23 additions and 22 deletions
|
|
@ -10,7 +10,6 @@ if (!channelID) {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
const assert = require("assert/strict")
|
||||
const sqlite = require("better-sqlite3")
|
||||
const backfill = new sqlite("scripts/backfill.db")
|
||||
backfill.prepare("CREATE TABLE IF NOT EXISTS backfill (channel_id TEXT NOT NULL, message_id INTEGER NOT NULL, PRIMARY KEY (channel_id, message_id))").run()
|
||||
|
|
@ -38,12 +37,8 @@ passthrough.select = orm.select
|
|||
|
||||
/** @type {import("../src/d2m/event-dispatcher")}*/
|
||||
const eventDispatcher = sync.require("../src/d2m/event-dispatcher")
|
||||
|
||||
const roomID = passthrough.select("channel_room", "room_id", {channel_id: channelID}).pluck().get()
|
||||
if (!roomID) {
|
||||
console.error("Please choose a channel that's already bridged.")
|
||||
process.exit(1)
|
||||
}
|
||||
/** @type {import("../src/d2m/actions/create-room")} */
|
||||
const createRoom = sync.require("../src/d2m/actions/create-room")
|
||||
|
||||
;(async () => {
|
||||
await discord.cloud.connect()
|
||||
|
|
@ -60,6 +55,8 @@ async function event(event) {
|
|||
if (!channel) return
|
||||
const guild_id = event.d.id
|
||||
|
||||
try {
|
||||
await createRoom.syncRoom(channelID)
|
||||
let last = backfill.prepare("SELECT cast(max(message_id) as TEXT) FROM backfill WHERE channel_id = ?").pluck().get(channelID) || "0"
|
||||
console.log(`OK, processing messages for #${channel.name}, continuing from ${last}`)
|
||||
|
||||
|
|
@ -79,4 +76,8 @@ async function event(event) {
|
|||
}
|
||||
|
||||
process.exit()
|
||||
} 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