From 574693362c9011b112b745c0cd117581a116d5c2 Mon Sep 17 00:00:00 2001 From: Prince527 Date: Mon, 29 Jul 2024 17:48:26 -0300 Subject: [PATCH] Fix Translate+ (#24) * Update translator.ts * Update index.tsx --- src/equicordplugins/translatePlus/index.tsx | 18 +++++++++++------- .../translatePlus/utils/translator.ts | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/equicordplugins/translatePlus/index.tsx b/src/equicordplugins/translatePlus/index.tsx index 3eb882d5..9ec6336d 100644 --- a/src/equicordplugins/translatePlus/index.tsx +++ b/src/equicordplugins/translatePlus/index.tsx @@ -58,13 +58,17 @@ export default definePlugin({ start() { addAccessory("ec-translation", props => ); - addButton("ec-translate", message => ({ - label: "Translate", - icon: Icon, - message: message, - channel: ChannelStore.getChannel(message.channel_id), - onClick: () => handleTranslate(message), - })); + addButton("ec-translate", message => { + if (!message.content) return null; + + return { + label: "Translate", + icon: Icon, + message: message, + channel: ChannelStore.getChannel(message.channel_id), + onClick: () => handleTranslate(message), + }; + }); }, stop() { removeButton("ec-translate"); diff --git a/src/equicordplugins/translatePlus/utils/translator.ts b/src/equicordplugins/translatePlus/utils/translator.ts index a5ea6a34..342165b9 100644 --- a/src/equicordplugins/translatePlus/utils/translator.ts +++ b/src/equicordplugins/translatePlus/utils/translator.ts @@ -25,7 +25,7 @@ function isShavian(text: string) { } async function translateShavian(message: string) { - const dictionary = await (await fetch("https://github.com/ForkPrince/TranslatePlus/raw/322199d5fdb1a9506591c9f4a2826338b5d67e38/shavian.json")).json(); + const dictionary = await (await fetch("https://raw.githubusercontent.com/ForkPrince/TranslatePlus/322199d5fdb1a9506591c9f4a2826338b5d67e38/shavian.json")).json(); const punctuationMap = { '"': "\"", @@ -72,7 +72,7 @@ async function translateShavian(message: string) { async function translateSitelen(message: string) { message = Array.from(message).join(" "); - const dictionary = await (await fetch("https://github.com/ForkPrince/TranslatePlus/raw/5ca152b134ea11433971f21b2ef8d556d4306717/sitelen-pona.json")).json(); + const dictionary = await (await fetch("https://raw.githubusercontent.com/ForkPrince/TranslatePlus/5ca152b134ea11433971f21b2ef8d556d4306717/sitelen-pona.json")).json(); const sorted = Object.keys(dictionary).sort((a, b) => b.length - a.length);