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.)
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 {

View file

@ -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)
}
/**

View file

@ -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)
}

View file

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