From 7defa7e644b805b83efdbc77a0356c162e943765 Mon Sep 17 00:00:00 2001 From: bignutty <3515180-bignutty@users.noreply.gitlab.com> Date: Tue, 15 Apr 2025 15:47:41 +0200 Subject: [PATCH] fix embed translation for ARTICLE type embeds --- commands/interaction/context/translate.js | 16 ++++++++++++---- commands/message/utils/translate.js | 15 +++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/commands/interaction/context/translate.js b/commands/interaction/context/translate.js index 2d4a1c0..6eaa7a3 100644 --- a/commands/interaction/context/translate.js +++ b/commands/interaction/context/translate.js @@ -11,6 +11,7 @@ const { ApplicationCommandTypes, InteractionCallbackTypes, InteractionContextTyp } = require("detritus-client/lib/constants"); const { Components } = require('detritus-client/lib/utils'); +// TODO(unity): utils/translate.js async function translateMessage(context, message, to, from){ let mappings = {}; @@ -27,7 +28,8 @@ async function translateMessage(context, message, to, from){ // Message Translation supports Descriptions and Fields for(const e of message.embeds){ let emb = e[1] - if(e[1].type !== MessageEmbedTypes.RICH) continue; + + if(![MessageEmbedTypes.ARTICLE,MessageEmbedTypes.RICH].includes(emb.type)) continue; if(emb.description) mappings["embeds/" + i + "/description"] = emb.description; if(emb.title) mappings["embeds/" + i + "/title"] = emb.title; if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name; @@ -66,17 +68,23 @@ async function translateMessage(context, message, to, from){ // Message Translation supports Descriptions and Fields for(const e of message.embeds){ let emb = e[1] - if(e[1].type !== MessageEmbedTypes.RICH) continue; + + if(![MessageEmbedTypes.ARTICLE,MessageEmbedTypes.RICH].includes(emb.type)) continue; let newEmbed = { fields: [] }; // Elements we don't translate if(emb.color) newEmbed.color = emb.color; - if(emb.thumbnail) newEmbed.thumbnail = emb.thumbnail; - if(emb.image) newEmbed.image = emb.image; if(emb.url) newEmbed.url = emb.url; + if(emb.thumbnail){ + // Special Case, articles render differently + if(emb.type === MessageEmbedTypes.ARTICLE) newEmbed.image = emb.thumbnail; + else newEmbed.thumbnail = emb.thumbnail; + } + if(emb.image) newEmbed.image = emb.image; + if(emb.title) newEmbed.title = stringwrap(tr["embeds/" + i + "/title"], 256); if(emb.description) newEmbed.description = stringwrap(tr["embeds/" + i + "/description"], 4096); diff --git a/commands/message/utils/translate.js b/commands/message/utils/translate.js index 068204f..5bb277a 100644 --- a/commands/message/utils/translate.js +++ b/commands/message/utils/translate.js @@ -27,8 +27,8 @@ async function translateMessage(context, message, to, from){ // Message Translation supports Descriptions and Fields for(const e of message.embeds){ let emb = e[1]; - if(e[1].type !== MessageEmbedTypes.RICH) continue; + if(![MessageEmbedTypes.ARTICLE,MessageEmbedTypes.RICH].includes(emb.type)) continue; if(emb.description) mappings["embeds/" + i + "/description"] = emb.description; if(emb.title) mappings["embeds/" + i + "/title"] = emb.title; if(emb.author?.name) mappings["embeds/" + i + "/author/name"] = emb.author.name; @@ -68,17 +68,24 @@ async function translateMessage(context, message, to, from){ for(const e of message.embeds){ let emb = e[1] - if(e[1].type !== MessageEmbedTypes.RICH) continue; + if(![MessageEmbedTypes.ARTICLE,MessageEmbedTypes.RICH].includes(emb.type)) continue; let newEmbed = { fields: [] }; // Elements we don't translate if(emb.color) newEmbed.color = emb.color; - if(emb.thumbnail) newEmbed.thumbnail = emb.thumbnail; - if(emb.image) newEmbed.image = emb.image; if(emb.url) newEmbed.url = emb.url; + if(emb.thumbnail){ + // Special Case, articles render differently + if(emb.type === MessageEmbedTypes.ARTICLE) newEmbed.image = emb.thumbnail; + else newEmbed.thumbnail = emb.thumbnail; + } + + if(emb.image) newEmbed.image = emb.image; + + if(emb.title) newEmbed.title = stringwrap(tr["embeds/" + i + "/title"], 256); if(emb.description) newEmbed.description = stringwrap(tr["embeds/" + i + "/description"], 4096);