Skip to content

Commit

Permalink
fix(FakeNitro): implement option to toggle hyperlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
janisslsm committed Apr 9, 2024
1 parent 08f13f8 commit e706f4f
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions plugins/FakeNitro/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,43 @@ const { getGuildId } = findByStoreName("SelectedGuildStore");
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
const emoji = getCustomEmojiById(emojiString[2]);
// Check emoji usability
if (
emoji.guildId != getGuildId() ||
emoji.animated
) {
// Remove emote from original msg
messageString = messageString.replace(emojiString[0], "");
// Add to emotes to send
emojiUrls.push(`[${emoji.name}](${emoji.url.split("?")[0]}?size=${size}&name=${emoji.name})`);
}
}

return {
const emojiStrings = messageString.matchAll(/<a?:(\w+):(\d+)>/gi);
const emojiUrls = [];

for (const emojiString of emojiStrings) {
// Fetch required info about the emoji
const emoji = getCustomEmojiById(emojiString[2]);
// Check emoji usability
if (
emoji.guildId != getGuildId() ||
emoji.animated
) {
// Remove emote from original msg
messageString = messageString.replace(emojiString[0], "");
// Add to emotes to send
if (storage.hyperLink === true)
emojiUrls.push(`[${emoji.name}](${emoji.url.split("?")[0]}?size=${size}&name=${emoji.name})`);
else
emojiUrls.push(`${emoji.url.split("?")[0]}?size=${size}&name=${emoji.name}`);
}
}

return {
newContent: messageString.trim(),
extractedEmojis: emojiUrls,
};
}

export default function modifyIfNeeded(msg: Message) {
if (!msg.content.match(hasEmotesRegex)) return;
if (!msg.content.match(hasEmotesRegex)) 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, extractedEmojis } = extractUnusableEmojis(msg.content, storage.emojiSize);

msg.content = newContent;
msg.content = newContent;

if (extractedEmojis.length > 0) msg.content += "\n" + extractedEmojis.join("\n");
if (extractedEmojis.length > 0) msg.content += "\n" + extractedEmojis.join("\n");

// Set invalidEmojis to empty to prevent Discord yelling to you about you not having nitro
msg.invalidEmojis = [];
// Set invalidEmojis to empty to prevent Discord yelling to you about you not having nitro
msg.invalidEmojis = [];
};

0 comments on commit e706f4f

Please sign in to comment.