From a5b8ba64789e0b30dee3e3fbd257eb25877395e1 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 12 Apr 2023 23:20:17 +0200 Subject: [PATCH] bridge: fetch message author if unknown --- bridge/src/revolt/events.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bridge/src/revolt/events.ts b/bridge/src/revolt/events.ts index 55859da..24ab77f 100644 --- a/bridge/src/revolt/events.ts +++ b/bridge/src/revolt/events.ts @@ -90,6 +90,8 @@ client.on("messageUpdate", async (message) => { try { logger.debug(`[E] Revolt: ${message.content}`); + if (!message.author) await client.users.fetch(message.authorId!); + const [bridgeCfg, bridgedMsg] = await Promise.all([ BRIDGE_CONFIG.findOne({ revolt: message.channelId }), BRIDGED_MESSAGES.findOne({ "revolt.nonce": message.nonce }), @@ -111,15 +113,15 @@ client.on("messageUpdate", async (message) => { if (!targetMsg) return logger.debug(`Revolt: Could not fetch message from Discord`); - const client = new WebhookClient({ + const webhookClient = new WebhookClient({ id: bridgeCfg.discordWebhook.id, token: bridgeCfg.discordWebhook.token, }); - await client.editMessage(targetMsg, { + await webhookClient.editMessage(targetMsg, { content: await renderMessageBody(message.content), allowedMentions: { parse: [] }, }); - client.destroy(); + webhookClient.destroy(); metrics.messages.inc({ source: "revolt", type: "edit" }); } catch (e) { @@ -131,6 +133,8 @@ client.on("messageCreate", async (message) => { try { logger.debug(`[M] Revolt: ${message.id} ${message.content}`); + if (!message.author) await client.users.fetch(message.authorId!); + const [bridgeCfg, bridgedMsg, ...repliedMessages] = await Promise.all([ BRIDGE_CONFIG.findOne({ revolt: message.channelId }), BRIDGED_MESSAGES.findOne( @@ -229,7 +233,7 @@ client.on("messageCreate", async (message) => { const channel = (await discordClient.channels.fetch( bridgeCfg.discord )) as TextChannel; - const client = new WebhookClient({ + const webhookClient = new WebhookClient({ id: bridgeCfg.discordWebhook!.id, token: bridgeCfg.discordWebhook!.token, }); @@ -373,7 +377,7 @@ client.on("messageCreate", async (message) => { } } - client + webhookClient .send(payload) .then(async (res) => { await BRIDGED_MESSAGES.update(