Code quality

This commit is contained in:
Cadence Ember 2025-02-20 11:36:51 +13:00
parent 6eed4ec54a
commit fbc1b6f419
4 changed files with 12 additions and 12 deletions

View file

@ -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.) // (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.transaction(() => {
db.prepare("DELETE FROM channel_room WHERE channel_id = ?").run(channel.id) 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)`) console.log(`-- -- Added to database (transferred properties from previous OOYE room)`)
})() })()
} else { } else {

View file

@ -480,22 +480,22 @@ async function unbridgeDeletedChannel(channel, guildID) {
// remove room from being a space member // remove room from being a space member
await api.sendState(roomID, "m.space.parent", row.space_id, {}) await api.sendState(roomID, "m.space.parent", row.space_id, {})
await api.sendState(row.space_id, "m.space.child", roomID, {}) 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 // 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) // (the room can be used with less clutter and the member list makes sense if it's bridged somewhere else)
if (row.autocreate === 0) { if (row.autocreate === 0) {
// remove sim members // 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 = ?") const preparedDelete = db.prepare("DELETE FROM sim_member WHERE room_id = ? AND mxid = ?")
for (const mxid of members) { for (const mxid of members) {
await api.leaveRoom(roomID, mxid) await api.leaveRoom(roomID, mxid)
preparedDelete.run(roomID, mxid) preparedDelete.run(roomID, mxid)
} }
} }
// leave room
await api.leaveRoom(roomID)
} }
/** /**

View file

@ -6,9 +6,8 @@ const DiscordTypes = require("discord-api-types/v10")
const passthrough = require("../passthrough") const passthrough = require("../passthrough")
const {sync, db} = passthrough const {sync, db} = passthrough
function populateGuildID(guildID, channelID) { /** @type {{run: (guildID: string, channelID: string) => any}} */
db.prepare("UPDATE channel_room SET guild_id = ? WHERE channel_id = ?").run(guildID, channelID) const populateGuildID = db.prepare("UPDATE channel_room SET guild_id = ? WHERE channel_id = ?")
}
const utils = { const utils = {
/** /**
@ -40,14 +39,14 @@ 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) populateGuildID.run(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) populateGuildID.run(message.d.id, thread.id)
} }
if (listen === "full") { if (listen === "full") {
@ -104,7 +103,7 @@ 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"]) { 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"]) 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)
} }
@ -132,7 +131,7 @@ const utils = {
} else if (message.t === "CHANNEL_CREATE") { } else 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) populateGuildID.run(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)
} }

View file

@ -105,6 +105,7 @@ module.exports = {
} }
}, },
guild: { guild: {
/** @type {DiscordTypes.APIGuild} */ // @ts-ignore
general: { general: {
owner_id: "112760500130975744", owner_id: "112760500130975744",
premium_tier: 3, premium_tier: 3,