Create and populate guild_id column

This commit is contained in:
Cadence Ember 2024-10-05 02:23:58 +13:00
parent 5a86c07eb9
commit 6f7ed829b8
6 changed files with 33 additions and 21 deletions

View file

@ -39,7 +39,6 @@ const passthrough = require("../src/passthrough")
const db = new sqlite("ooye.db") const db = new sqlite("ooye.db")
const migrate = require("../src/db/migrate") const migrate = require("../src/db/migrate")
/** @type {import("heatsync").default} */ // @ts-ignore
const sync = new HeatSync({watchFS: false}) const sync = new HeatSync({watchFS: false})
Object.assign(passthrough, {sync, db}) Object.assign(passthrough, {sync, db})

View file

@ -12,7 +12,6 @@ const {reg} = require("../src/matrix/read-registration")
const passthrough = require("../src/passthrough") const passthrough = require("../src/passthrough")
const db = new sqlite("ooye.db") const db = new sqlite("ooye.db")
/** @type {import("heatsync").default} */ // @ts-ignore
const sync = new HeatSync() const sync = new HeatSync()
Object.assign(passthrough, {sync, db}) Object.assign(passthrough, {sync, db})

View file

@ -4,7 +4,11 @@
const DiscordTypes = require("discord-api-types/v10") const DiscordTypes = require("discord-api-types/v10")
const passthrough = require("../passthrough") const passthrough = require("../passthrough")
const { sync } = passthrough const {sync, db} = passthrough
function populateGuildID(guildID, channelID) {
db.prepare("UPDATE channel_room SET guild_id = ? WHERE channel_id = ?").run(guildID, channelID)
}
const utils = { const utils = {
/** /**
@ -36,13 +40,16 @@ const utils = {
channel.guild_id = message.d.id channel.guild_id = message.d.id
arr.push(channel.id) arr.push(channel.id)
client.channels.set(channel.id, channel) client.channels.set(channel.id, channel)
populateGuildID(message.d.id, channel.id)
} }
for (const thread of message.d.threads || []) { for (const thread of message.d.threads || []) {
// @ts-ignore // @ts-ignore
thread.guild_id = message.d.id thread.guild_id = message.d.id
arr.push(thread.id) arr.push(thread.id)
client.channels.set(thread.id, thread) client.channels.set(thread.id, thread)
populateGuildID(message.d.id, thread.id)
} }
if (listen === "full") { if (listen === "full") {
eventDispatcher.checkMissedExpressions(message.d) eventDispatcher.checkMissedExpressions(message.d)
eventDispatcher.checkMissedPins(client, message.d) eventDispatcher.checkMissedPins(client, message.d)
@ -91,7 +98,11 @@ const utils = {
} else if (message.t === "THREAD_CREATE") { } else if (message.t === "THREAD_CREATE") {
client.channels.set(message.d.id, message.d) client.channels.set(message.d.id, message.d)
if (message.d["guild_id"]) {
populateGuildID(message.d["guild_id"], message.d.id)
const channels = client.guildChannelMap.get(message.d["guild_id"])
if (channels && !channels.includes(message.d.id)) channels.push(message.d.id)
}
} else if (message.t === "CHANNEL_UPDATE" || message.t === "THREAD_UPDATE") { } else if (message.t === "CHANNEL_UPDATE" || message.t === "THREAD_UPDATE") {
client.channels.set(message.d.id, message.d) client.channels.set(message.d.id, message.d)
@ -113,21 +124,21 @@ const utils = {
client.guildChannelMap.delete(message.d.id) client.guildChannelMap.delete(message.d.id)
} else if (message.t === "CHANNEL_CREATE" || message.t === "CHANNEL_DELETE") { } else if (message.t === "CHANNEL_CREATE") {
if (message.t === "CHANNEL_CREATE") { client.channels.set(message.d.id, message.d)
client.channels.set(message.d.id, message.d) if (message.d["guild_id"]) { // obj[prop] notation can be used to access a property without typescript complaining that it doesn't exist on all values something can have
if (message.d["guild_id"]) { // obj[prop] notation can be used to access a property without typescript complaining that it doesn't exist on all values something can have populateGuildID(message.d["guild_id"], message.d.id)
const channels = client.guildChannelMap.get(message.d["guild_id"]) const channels = client.guildChannelMap.get(message.d["guild_id"])
if (channels && !channels.includes(message.d.id)) channels.push(message.d.id) if (channels && !channels.includes(message.d.id)) channels.push(message.d.id)
} }
} else {
client.channels.delete(message.d.id) } else if (message.t === "CHANNEL_DELETE") {
if (message.d["guild_id"]) { client.channels.delete(message.d.id)
const channels = client.guildChannelMap.get(message.d["guild_id"]) if (message.d["guild_id"]) {
if (channels) { const channels = client.guildChannelMap.get(message.d["guild_id"])
const previous = channels.indexOf(message.d.id) if (channels) {
if (previous !== -1) channels.splice(previous, 1) const previous = channels.indexOf(message.d.id)
} if (previous !== -1) channels.splice(previous, 1)
} }
} }
} }

View file

@ -0,0 +1,5 @@
BEGIN TRANSACTION;
ALTER TABLE channel_room ADD COLUMN guild_id TEXT;
COMMIT;

View file

@ -9,7 +9,6 @@ const {reg} = require("./src/matrix/read-registration")
const passthrough = require("./src/passthrough") const passthrough = require("./src/passthrough")
const db = new sqlite("ooye.db") const db = new sqlite("ooye.db")
/** @type {import("heatsync").default} */ // @ts-ignore
const sync = new HeatSync() const sync = new HeatSync()
Object.assign(passthrough, {sync, db}) Object.assign(passthrough, {sync, db})

View file

@ -25,7 +25,6 @@ reg.as_token = "baby"
reg.hs_token = "baby" reg.hs_token = "baby"
reg.ooye.bridge_origin = "https://bridge.example.org" reg.ooye.bridge_origin = "https://bridge.example.org"
/** @type {import("heatsync").default} */ // @ts-ignore
const sync = new HeatSync({watchFS: false}) const sync = new HeatSync({watchFS: false})
const discord = { const discord = {