1 |
rakin |
344 |
import { CommandInteraction, Message, Util } from 'discord.js'; |
2 |
rakin |
54 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
rakin |
344 |
import { timeSince } from '../../utils/util'; |
7 |
rakin |
54 |
import MessageEmbed from '../../client/MessageEmbed'; |
8 |
|
|
|
9 |
|
|
export default class EmojiCommand extends BaseCommand { |
10 |
|
|
supportsInteractions: boolean = true; |
11 |
|
|
|
12 |
|
|
constructor() { |
13 |
|
|
super('emoji', 'information', []); |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
17 |
|
|
if (!options.isInteraction && options.args[0] === undefined) { |
18 |
|
|
await msg.reply({ |
19 |
|
|
embeds: [ |
20 |
|
|
new MessageEmbed() |
21 |
|
|
.setColor('#f14a60') |
22 |
|
|
.setDescription(':x: This command requires at least one argument.') |
23 |
|
|
] |
24 |
|
|
}); |
25 |
|
|
|
26 |
|
|
return; |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
let emojiString: string; |
30 |
|
|
|
31 |
|
|
if (options.isInteraction) { |
32 |
|
|
emojiString = await <string> options.options.getString('emoji'); |
33 |
|
|
} |
34 |
|
|
else { |
35 |
|
|
emojiString = options.args[0]; |
36 |
|
|
} |
37 |
|
|
|
38 |
rakin |
314 |
const emojiSubString = emojiString.startsWith('<:') && emojiString.endsWith('>') ? emojiString.substring(2, emojiString.length - 1) : emojiString; |
39 |
rakin |
54 |
|
40 |
rakin |
314 |
let emoji = await client.emojis.cache.find(e => e.name === emojiSubString || e.identifier === emojiSubString || e.id === emojiSubString); |
41 |
rakin |
54 |
|
42 |
|
|
if (!emoji) { |
43 |
rakin |
314 |
if ((emojiString.startsWith('<:') && emojiString.endsWith('>')) || /\d+/g.test(emojiString)) { |
44 |
|
|
let parsedEmoji = emojiString.startsWith('<:') && emojiString.endsWith('>') ? Util.parseEmoji(emojiString) : { animated: undefined, id: emojiString, name: undefined }; |
45 |
rakin |
54 |
|
46 |
rakin |
314 |
if (!parsedEmoji) { |
47 |
|
|
await msg.reply({ |
48 |
|
|
embeds: [ |
49 |
|
|
new MessageEmbed() |
50 |
|
|
.setColor('#f14a60') |
51 |
|
|
.setDescription('Invalid emoji!') |
52 |
|
|
] |
53 |
|
|
}); |
54 |
|
|
|
55 |
|
|
return; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
await msg.reply({ |
59 |
|
|
embeds: [ |
60 |
|
|
new MessageEmbed() |
61 |
|
|
.setAuthor({ |
62 |
|
|
name: parsedEmoji.name ?? "Unknown Emoji", |
63 |
|
|
iconURL: `https://cdn.discordapp.com/emojis/${parsedEmoji.id}`, |
64 |
|
|
}) |
65 |
|
|
.setFields({ |
66 |
|
|
name: "Animated", |
67 |
|
|
value: parsedEmoji.animated !== undefined ? parsedEmoji.animated ? 'Yes' : 'No' : "*The system could not load enough information*", |
68 |
|
|
}, { |
69 |
|
|
name: "Download", |
70 |
|
|
value: `[Click Here](https://cdn.discordapp.com/emojis/${parsedEmoji.id})` |
71 |
|
|
}) |
72 |
|
|
.setThumbnail(`https://cdn.discordapp.com/emojis/${parsedEmoji.id}`) |
73 |
|
|
.setFooter({ |
74 |
|
|
text: `ID: ${parsedEmoji.id}` |
75 |
|
|
}) |
76 |
|
|
] |
77 |
|
|
}); |
78 |
|
|
} |
79 |
|
|
else { |
80 |
|
|
await msg.reply({ |
81 |
|
|
embeds: [ |
82 |
|
|
new MessageEmbed() |
83 |
|
|
.setColor('#f14a60') |
84 |
|
|
.setDescription('No emoji found or not a guild based emoji!') |
85 |
|
|
] |
86 |
|
|
}); |
87 |
|
|
} |
88 |
|
|
|
89 |
rakin |
54 |
return; |
90 |
rakin |
314 |
} |
91 |
rakin |
54 |
|
92 |
|
|
await msg.reply({ |
93 |
|
|
embeds: [ |
94 |
|
|
new MessageEmbed() |
95 |
|
|
.setAuthor({ |
96 |
|
|
name: emoji.guild.name, |
97 |
|
|
iconURL: emoji.guild.iconURL()!, |
98 |
|
|
}) |
99 |
|
|
.setTitle(emoji.name ?? 'Emoji Information') |
100 |
|
|
.addField('Name', emoji.name ?? '*No name set*') |
101 |
|
|
.addField('Identifier', emoji.identifier ?? '*No identifier set*') |
102 |
|
|
.addField('Available', emoji.available ? 'Yes' : 'No') |
103 |
rakin |
314 |
.addField('Created', timeSince(emoji.createdAt.getTime())) |
104 |
rakin |
54 |
.addField('Download', `[Click here](${emoji.url})`) |
105 |
rakin |
314 |
.setThumbnail(emoji.url) |
106 |
rakin |
54 |
.setFooter({ |
107 |
|
|
text: `ID: ${emoji.id}` |
108 |
|
|
}) |
109 |
|
|
] |
110 |
|
|
}); |
111 |
|
|
} |
112 |
|
|
} |