From 57e2995611704943338d9ad676d5e067b61e3bd1 Mon Sep 17 00:00:00 2001 From: Rico040 <93081680+Rico040@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:50:57 +0900 Subject: [PATCH] Freemoji: no `\n` yes `string.replace()` --- plugins/freemoji/src/msgProcessor.ts | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/plugins/freemoji/src/msgProcessor.ts b/plugins/freemoji/src/msgProcessor.ts index 50d6c46..200c71b 100644 --- a/plugins/freemoji/src/msgProcessor.ts +++ b/plugins/freemoji/src/msgProcessor.ts @@ -9,7 +9,6 @@ const hasEmotesRegex = //i; function extractUnusableEmojis(messageString: string, size: number) { const emojiStrings = messageString.matchAll(//gi); - const emojiUrls = []; for (const emojiString of emojiStrings) { // Fetch required info about the emoji @@ -20,23 +19,26 @@ function extractUnusableEmojis(messageString: string, size: number) { emoji.guildId != getGuildId() || emoji.animated ) { - // Remove emote from original msg - messageString = messageString.replace(emojiString[0], ""); // Add to emotes to send // Hacky fix, someone on discord removed url property for emoji var ext = "webp" if (emoji.animated){ ext = "gif"; } if (storage.hyperlink === true) { - emojiUrls.push(`[${emojiString[1]}](https://cdn.discordapp.com/emojis/${emojiString[2]}.${ext}?size=${size}&quality=lossless&name=${emojiString[1]})`); + messageString = messageString.replace( + emojiString[0], + `[${emojiString[1]}](https://cdn.discordapp.com/emojis/${emojiString[2]}.${ext}?size=${size}&quality=lossless&name=${emojiString[1]})` + ); } else { - emojiUrls.push(`https://cdn.discordapp.com/emojis/${emojiString[2]}.${ext}?size=${size}&quality=lossless&name=${emojiString[1]}`); + messageString = messageString.replace( + emojiString[0], + `https://cdn.discordapp.com/emojis/${emojiString[2]}.${ext}?size=${size}&quality=lossless&name=${emojiString[1]}` + ); } } } return { - newContent: messageString.trim(), - extractedEmojis: emojiUrls, + newContent: messageString.trim() }; } @@ -44,18 +46,18 @@ export default function modifyIfNeeded(msg: Message) { if (!msg.content.match(hasEmotesRegex)) return; if (!storage.forceMoji) { if (storage.haveNitro) return; } - // Find all emojis from the captured message string and return object with emojiURLS and content - const { newContent, extractedEmojis } = extractUnusableEmojis(msg.content, storage.emojiSize); + // Find all emojis from the captured message string and return object with ~~emojiURLS and~~ content + const { newContent } = extractUnusableEmojis(msg.content, storage.emojiSize); msg.content = newContent; - if (extractedEmojis.length > 0) { - if (storage.hyperlink === true) { - msg.content += " " + extractedEmojis.join(" "); - } else { - msg.content += "\n" + extractedEmojis.join("\n"); - } - } + // if (extractedEmojis.length > 0) { + // if (storage.hyperlink === true) { + // msg.content += " " + extractedEmojis.join(" "); + // } else { + // msg.content += "\n" + extractedEmojis.join("\n"); + // } + // } // Set invalidEmojis to empty to prevent Discord yelling to you about you not having nitro msg.invalidEmojis = [];