Skip to content

Commit

Permalink
Freemoji: no \n yes string.replace()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico040 committed Aug 13, 2024
1 parent 4379692 commit 57e2995
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions plugins/freemoji/src/msgProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const hasEmotesRegex = /<a?:(\w+):(\d+)>/i;

function extractUnusableEmojis(messageString: string, size: number) {
const emojiStrings = messageString.matchAll(/<a?:(\w+):(\d+)>/gi);
const emojiUrls = [];

for (const emojiString of emojiStrings) {
// Fetch required info about the emoji
Expand All @@ -20,42 +19,45 @@ 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()
};
}

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 = [];
Expand Down

0 comments on commit 57e2995

Please sign in to comment.