Skip to content

Commit

Permalink
Update download-emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jan 2, 2025
1 parent aa3e795 commit 02c158e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
53 changes: 23 additions & 30 deletions commands/Fun/download-emoji.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const Command = require('../../base/Command.js');
const emojiRegex = require('emoji-regex');
const twemoji = require('twemoji');

class DownloadEmoji extends Command {
constructor(client) {
Expand All @@ -18,49 +16,44 @@ class DownloadEmoji extends Command {
async run(msg, args) {
const content = args.join(' ');
const result = [];
const res = [];
// Helper function to get code points for Unicode emojis
const toCodePoint = (emoji) => [...emoji].map((char) => char.codePointAt(0).toString(16)).join('-');

// Normal Emojis
// Match Normal Unicode Emojis
const emojiRegex = require('emoji-regex');
const normalEmojis = content.match(emojiRegex());
if (normalEmojis) {
normalEmojis.forEach((emoji) => {
result.push(emoji);
const codePoint = toCodePoint(emoji);
const url = `https://cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets/72x72/${codePoint}.png`;
result.push(url);
});
}

// Client Emojis
let clientEmojis = content.match(/:[_a-zA-Z0-9]*>/g);
// Match Client Emojis (Static and Animated)
const clientEmojis = content.match(/<a?:\w+:(\d+)>/g);
if (clientEmojis) {
clientEmojis = clientEmojis.map((e) => e.substring(1, e.length - 1));
clientEmojis.forEach((e) => {
const e1 = e.replace(/[^\d]/g, '');
const clientEmoji = this.client.emojis.resolveIdentifier(e1);
if (clientEmoji) result.push(clientEmoji);
clientEmojis.forEach((emoji) => {
const emojiId = emoji.match(/:(\d+)>/)[1];
const isAnimated = emoji.startsWith('<a:');
const url = `https://cdn.discordapp.com/emojis/${emojiId}${isAnimated ? '.gif' : '.png'}`;
result.push(url);
});
}

if (result.length < 1) {
if (result.length === 0) {
return this.client.util.errorEmbed(msg, 'You need to input at least one emoji.');
}

result.forEach((emoji) => {
if (emoji.replace(/[^\d]/g, '').length > 1) {
res.push(
`https://cdn.discordapp.com/emojis/${emoji.replace(/[^\d]/g, '')}${
emoji.charAt(0) === 'a' ? '.gif' : '.png'
}`,
);
} else {
const out = twemoji.parse(emoji);
res.push(out.split('src="')[1].replace(/"\/>/g, ''));
}
});
const emojis = res.splice(0, 10);
const text = emojis.length > 1 ? 'Here are your emojis:' : 'Here is your emoji:';

return msg.channel.send({ content: text, files: emojis });
try {
const emojis = result.slice(0, 10); // Limit to 10 emojis
const text = emojis.length > 1 ? 'Here are your emojis:' : 'Here is your emoji:';
return msg.channel.send({ content: text, files: emojis });
} catch (error) {
console.error('Error while processing emojis:', error);
return msg.channel.send('An error occurred while processing your request.');
}
}
}

module.exports = DownloadEmoji;
// Special credits to CoolGuy#9889 and Redi Panda_#0247
52 changes: 44 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@distube/ytdl-core": "^4.15.1",
"@justalk/pornhub-api": "^3.5.0",
"@mapbox/node-pre-gyp": "^1.0.9",
"@twemoji/api": "^15.1.0",
"better-sqlite3": "^7.4.1",
"blackjack-n-deck": "^1.0.1",
"botlist.me.js": "^1.0.2",
Expand All @@ -38,7 +39,7 @@
"discord-html-transcripts": "^3.2.0",
"discord-player": "^6.6.10",
"discord.js": "^14.15.3",
"emoji-regex": "^10.1.0",
"emoji-regex": "^10.4.0",
"enmap": "^5.8.6",
"fluent-ffmpeg": "^2.1.2",
"is-image-url": "^1.1.8",
Expand Down Expand Up @@ -67,7 +68,6 @@
"superagent": "^8.0.0",
"tictactoe-minimax-ai": "github:lukechu10/tictactoe-minimax",
"trev-reborn": "^1.2.0",
"twemoji": "^14.0.2",
"undici": "^5.28.4",
"weather-js": "^2.0.0",
"youtube-sr": "^4.3.4"
Expand Down

0 comments on commit 02c158e

Please sign in to comment.