1
0
Fork 0

synchronise channel updates

This commit is contained in:
Cadence Ember 2023-08-19 23:12:36 +12:00
parent 3436759504
commit 08d3f3d804
3 changed files with 29 additions and 3 deletions

View file

@ -252,8 +252,11 @@ async function createAllForGuild(guildID) {
const channelIDs = discord.guildChannelMap.get(guildID) const channelIDs = discord.guildChannelMap.get(guildID)
assert.ok(channelIDs) assert.ok(channelIDs)
for (const channelID of channelIDs) { for (const channelID of channelIDs) {
if (discord.channels.get(channelID)?.type === DiscordTypes.ChannelType.GuildText) { // TODO: guild sync thread channels and such. maybe make a helper function to check if a given channel is syncable? const allowedTypes = [DiscordTypes.ChannelType.GuildText, DiscordTypes.ChannelType.PublicThread]
await syncRoom(channelID).then(r => console.log(`synced ${channelID}:`, r)) // @ts-ignore
if (allowedTypes.includes(discord.channels.get(channelID)?.type)) {
const roomID = await syncRoom(channelID)
console.log(`synced ${channelID} <-> ${roomID}`)
} }
} }
} }

View file

@ -44,6 +44,10 @@ const utils = {
eventDispatcher.checkMissedMessages(client, message.d) eventDispatcher.checkMissedMessages(client, message.d)
} else if (message.t === "CHANNEL_UPDATE" || message.t === "THREAD_UPDATE") {
client.channels.set(message.d.id, message.d)
} else if (message.t === "GUILD_DELETE") { } else if (message.t === "GUILD_DELETE") {
client.guilds.delete(message.d.id) client.guilds.delete(message.d.id)
const channels = client.guildChannelMap.get(message.d.id) const channels = client.guildChannelMap.get(message.d.id)
@ -74,7 +78,13 @@ const utils = {
// Event dispatcher for OOYE bridge operations // Event dispatcher for OOYE bridge operations
try { try {
if (message.t === "MESSAGE_CREATE") { if (message.t === "CHANNEL_UPDATE") {
await eventDispatcher.onChannelOrThreadUpdate(client, message.d, false)
} else if (message.t === "THREAD_UPDATE") {
await eventDispatcher.onChannelOrThreadUpdate(client, message.d, true)
} else if (message.t === "MESSAGE_CREATE") {
await eventDispatcher.onMessageCreate(client, message.d) await eventDispatcher.onMessageCreate(client, message.d)
} else if (message.t === "MESSAGE_UPDATE") { } else if (message.t === "MESSAGE_UPDATE") {

View file

@ -10,6 +10,8 @@ const editMessage = sync.require("./actions/edit-message")
const deleteMessage = sync.require("./actions/delete-message") const deleteMessage = sync.require("./actions/delete-message")
/** @type {import("./actions/add-reaction")}) */ /** @type {import("./actions/add-reaction")}) */
const addReaction = sync.require("./actions/add-reaction") const addReaction = sync.require("./actions/add-reaction")
/** @type {import("./actions/create-room")}) */
const createRoom = sync.require("./actions/create-room")
/** @type {import("../matrix/api")}) */ /** @type {import("../matrix/api")}) */
const api = sync.require("../matrix/api") const api = sync.require("../matrix/api")
@ -99,6 +101,17 @@ module.exports = {
} }
}, },
/**
* @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayChannelUpdateDispatchData} channelOrThread
* @param {boolean} isThread
*/
async onChannelOrThreadUpdate(client, channelOrThread, isThread) {
const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").get(channelOrThread.id)
if (!roomID) return // No target room to update the data on
await createRoom.syncRoom(channelOrThread.id)
},
/** /**
* @param {import("./discord-client")} client * @param {import("./discord-client")} client
* @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message * @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message