WIP: auto-create bridged rooms if they don't exist #75
1 changed files with 14 additions and 6 deletions
|
|
@ -38,12 +38,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 +56,18 @@ async function event(event) {
|
|||
if (!channel) return
|
||||
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 {
|
||||
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"
|
||||
console.log(`OK, processing messages for #${channel.name}, continuing from ${last}`)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue