From d54edfdeed1ea8d8d1fe99e4e0d8af711bfccfe3 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Tue, 19 Apr 2022 12:01:06 +0200 Subject: [PATCH] message deletions discord->revolt --- bridge/src/discord/events.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bridge/src/discord/events.ts b/bridge/src/discord/events.ts index 293c3f9..9c21a1b 100644 --- a/bridge/src/discord/events.ts +++ b/bridge/src/discord/events.ts @@ -10,6 +10,27 @@ import { revoltFetchMessage } from "../util"; const MAX_BRIDGED_FILE_SIZE = 8_000_000; // 8 MB +client.on('messageDelete', async message => { + try { + logger.debug(`[D] Discord: ${message.id}`); + + const [ bridgeCfg, bridgedMsg ] = await Promise.all([ + BRIDGE_CONFIG.findOne({ discord: message.channelId }), + BRIDGED_MESSAGES.findOne({ "discord.messageId": message.id }), + ]); + + if (!bridgedMsg?.revolt) return logger.debug(`Discord: Message has not been bridged; ignoring deletion`); + if (!bridgeCfg?.revolt) return logger.debug(`Discord: No Revolt channel associated`); + + const targetMsg = await revoltFetchMessage(bridgedMsg.revolt.messageId, revoltClient.channels.get(bridgeCfg.revolt)); + if (!targetMsg) return logger.debug(`Discord: Could not fetch message from Revolt`); + + await targetMsg.delete(); + } catch(e) { + console.error(e); + } +}); + client.on('messageUpdate', async (oldMsg, newMsg) => { if (oldMsg.content && newMsg.content == oldMsg.content) return; // Let's not worry about embeds here for now