synchronise channel updates
This commit is contained in:
parent
3436759504
commit
08d3f3d804
3 changed files with 29 additions and 3 deletions
|
@ -252,8 +252,11 @@ async function createAllForGuild(guildID) {
|
|||
const channelIDs = discord.guildChannelMap.get(guildID)
|
||||
assert.ok(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?
|
||||
await syncRoom(channelID).then(r => console.log(`synced ${channelID}:`, r))
|
||||
const allowedTypes = [DiscordTypes.ChannelType.GuildText, DiscordTypes.ChannelType.PublicThread]
|
||||
// @ts-ignore
|
||||
if (allowedTypes.includes(discord.channels.get(channelID)?.type)) {
|
||||
const roomID = await syncRoom(channelID)
|
||||
console.log(`synced ${channelID} <-> ${roomID}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,10 @@ const utils = {
|
|||
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") {
|
||||
client.guilds.delete(message.d.id)
|
||||
const channels = client.guildChannelMap.get(message.d.id)
|
||||
|
@ -74,7 +78,13 @@ const utils = {
|
|||
|
||||
// Event dispatcher for OOYE bridge operations
|
||||
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)
|
||||
|
||||
} else if (message.t === "MESSAGE_UPDATE") {
|
||||
|
|
|
@ -10,6 +10,8 @@ const editMessage = sync.require("./actions/edit-message")
|
|||
const deleteMessage = sync.require("./actions/delete-message")
|
||||
/** @type {import("./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")}) */
|
||||
const api = sync.require("../matrix/api")
|
||||
|
||||
|
@ -101,6 +103,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-api-types/v10").GatewayMessageCreateDispatchData} message
|
||||
*/
|
||||
async onMessageCreate(client, message) {
|
||||
|
|
Loading…
Reference in a new issue