Skip to content

Commit

Permalink
feat: add discord emoji previews
Browse files Browse the repository at this point in the history
  • Loading branch information
mayudev committed Apr 6, 2022
1 parent c8bc68c commit 26f6371
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function formatMessage(
// Handle emojis
const emojis = content.match(DiscordEmojiPattern);
if (emojis) {
emojis.forEach((emoji) => {
emojis.forEach((emoji, i) => {
const dissected = DiscordEmojiPattern.exec(emoji);

// reset internal pointer... what is that even
Expand All @@ -50,8 +50,18 @@ function formatMessage(
if (dissected !== null) {
const emojiName = dissected.groups["name"];
const emojiId = dissected.groups["id"];

if (emojiName && emojiId) {
content = content.replace(emoji, `[:${emojiName}:]()`);
let emojiUrl;

// Limit displayed emojis to 5 to reduce spam
if (i < 5) {
emojiUrl =
"https://cdn.discordapp.com/emojis/" +
emojiId +
".webp?size=32&quality=lossless";
}
content = content.replace(emoji, `[:${emojiName}:](${emojiUrl})`);
}
}
});
Expand Down

0 comments on commit 26f6371

Please sign in to comment.