forked from cadence/out-of-your-element
Compare commits
2 commits
16b63e2f2f
...
e382d67feb
| Author | SHA1 | Date | |
|---|---|---|---|
| e382d67feb | |||
| 3042db36ca |
1 changed files with 30 additions and 23 deletions
|
|
@ -10,6 +10,7 @@ if (!channelID) {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const assert = require("assert/strict")
|
||||||
const sqlite = require("better-sqlite3")
|
const sqlite = require("better-sqlite3")
|
||||||
const backfill = new sqlite("scripts/backfill.db")
|
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()
|
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()
|
||||||
|
|
@ -55,8 +56,18 @@ async function event(event) {
|
||||||
if (!channel) return
|
if (!channel) return
|
||||||
const guild_id = event.d.id
|
const guild_id = event.d.id
|
||||||
|
|
||||||
|
let roomID = passthrough.select("channel_room", "room_id", {channel_id: channelID}).pluck().get()
|
||||||
|
if (!roomID) {
|
||||||
|
console.log(`Channel #${channel.name} is not bridged yet. Attempting to auto-create...`)
|
||||||
try {
|
try {
|
||||||
await createRoom.syncRoom(channelID)
|
roomID = await createRoom.syncRoom(channelID)
|
||||||
|
console.log(`Successfully bridged to new room: ${roomID}`)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to auto-create room: ${e.message}`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let last = backfill.prepare("SELECT cast(max(message_id) as TEXT) FROM backfill WHERE channel_id = ?").pluck().get(channelID) || "0"
|
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}`)
|
console.log(`OK, processing messages for #${channel.name}, continuing from ${last}`)
|
||||||
|
|
||||||
|
|
@ -76,8 +87,4 @@ async function event(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
process.exit()
|
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