diff --git a/scripts/migrate-from-old-bridge.js b/scripts/migrate-from-old-bridge.js index c5e50a15..88a137c9 100755 --- a/scripts/migrate-from-old-bridge.js +++ b/scripts/migrate-from-old-bridge.js @@ -115,7 +115,7 @@ async function migrateGuild(guild) { // (By the way, thread_parent is always null here because thread rooms would never be migrated because they are not in the old bridge.) db.transaction(() => { db.prepare("DELETE FROM channel_room WHERE channel_id = ?").run(channel.id) - db.prepare("INSERT INTO channel_room (channel_id, room_id, name, nick, custom_avatar) VALUES (?, ?, ?, ?, ?)").run(channel.id, row.matrix_id, channel.name, preMigrationRow.nick, preMigrationRow.custom_avatar) + db.prepare("INSERT INTO channel_room (channel_id, room_id, name, nick, custom_avatar, guild_id) VALUES (?, ?, ?, ?, ?, ?)").run(channel.id, row.matrix_id, channel.name, preMigrationRow.nick, preMigrationRow.custom_avatar, guild.id) console.log(`-- -- Added to database (transferred properties from previous OOYE room)`) })() } else { diff --git a/src/d2m/actions/create-room.js b/src/d2m/actions/create-room.js index 3caf187e..0924631f 100644 --- a/src/d2m/actions/create-room.js +++ b/src/d2m/actions/create-room.js @@ -480,22 +480,22 @@ async function unbridgeDeletedChannel(channel, guildID) { // remove room from being a space member await api.sendState(roomID, "m.space.parent", row.space_id, {}) await api.sendState(row.space_id, "m.space.child", roomID, {}) - - // leave room - await api.leaveRoom(roomID) } // if it is a self-service room, remove sim members // (the room can be used with less clutter and the member list makes sense if it's bridged somewhere else) if (row.autocreate === 0) { // remove sim members - const members = select("sim_member", "mxid", {room_id: roomID}).pluck().all() + const members = db.prepare("SELECT mxid FROM sim_member WHERE room_id = ? AND mxid <> ?").pluck().all(roomID, bot) const preparedDelete = db.prepare("DELETE FROM sim_member WHERE room_id = ? AND mxid = ?") for (const mxid of members) { await api.leaveRoom(roomID, mxid) preparedDelete.run(roomID, mxid) } } + + // leave room + await api.leaveRoom(roomID) } /** diff --git a/src/d2m/discord-packets.js b/src/d2m/discord-packets.js index b9aba412..57ab24a9 100644 --- a/src/d2m/discord-packets.js +++ b/src/d2m/discord-packets.js @@ -6,9 +6,8 @@ const DiscordTypes = require("discord-api-types/v10") const passthrough = require("../passthrough") const {sync, db} = passthrough -function populateGuildID(guildID, channelID) { - db.prepare("UPDATE channel_room SET guild_id = ? WHERE channel_id = ?").run(guildID, channelID) -} +/** @type {{run: (guildID: string, channelID: string) => any}} */ +const populateGuildID = db.prepare("UPDATE channel_room SET guild_id = ? WHERE channel_id = ?") const utils = { /** @@ -40,14 +39,14 @@ const utils = { channel.guild_id = message.d.id arr.push(channel.id) client.channels.set(channel.id, channel) - populateGuildID(message.d.id, channel.id) + populateGuildID.run(message.d.id, channel.id) } for (const thread of message.d.threads || []) { // @ts-ignore thread.guild_id = message.d.id arr.push(thread.id) client.channels.set(thread.id, thread) - populateGuildID(message.d.id, thread.id) + populateGuildID.run(message.d.id, thread.id) } if (listen === "full") { @@ -104,7 +103,7 @@ const utils = { } else if (message.t === "THREAD_CREATE") { client.channels.set(message.d.id, message.d) if (message.d["guild_id"]) { - populateGuildID(message.d["guild_id"], message.d.id) + populateGuildID.run(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) } @@ -132,7 +131,7 @@ const utils = { } else if (message.t === "CHANNEL_CREATE") { 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 - populateGuildID(message.d["guild_id"], message.d.id) + populateGuildID.run(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) } diff --git a/test/data.js b/test/data.js index eebaaba7..b815b086 100644 --- a/test/data.js +++ b/test/data.js @@ -105,6 +105,7 @@ module.exports = { } }, guild: { + /** @type {DiscordTypes.APIGuild} */ // @ts-ignore general: { owner_id: "112760500130975744", premium_tier: 3,