1 |
import { CommandInteraction, Emoji, Message } from 'discord.js'; |
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
|
import { CommandInteraction, Message, Util } from 'discord.js'; |
21 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
22 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
23 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
24 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
25 |
import axios from 'axios'; |
import { timeSince } from '../../utils/util'; |
|
import path from 'path'; |
|
|
import { deleteFile, download, timeSince } from '../../utils/util'; |
|
26 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
27 |
|
|
28 |
export default class EmojiCommand extends BaseCommand { |
export default class EmojiCommand extends BaseCommand { |
54 |
emojiString = options.args[0]; |
emojiString = options.args[0]; |
55 |
} |
} |
56 |
|
|
57 |
if (emojiString.startsWith('<:') && emojiString.endsWith('>')) { |
const emojiSubString = emojiString.startsWith('<:') && emojiString.endsWith('>') ? emojiString.substring(2, emojiString.length - 1) : emojiString; |
|
console.log(emojiString); |
|
|
emojiString = emojiString.substring(2, emojiString.length - 1); |
|
|
} |
|
58 |
|
|
59 |
const emoji = await client.emojis.cache.find(e => e.name === emojiString || e.identifier === emojiString); |
let emoji = await client.emojis.cache.find(e => e.name === emojiSubString || e.identifier === emojiSubString || e.id === emojiSubString); |
60 |
|
|
61 |
if (!emoji) { |
if (!emoji) { |
62 |
await msg.reply({ |
if ((emojiString.startsWith('<:') && emojiString.endsWith('>')) || /\d+/g.test(emojiString)) { |
63 |
embeds: [ |
let parsedEmoji = emojiString.startsWith('<:') && emojiString.endsWith('>') ? Util.parseEmoji(emojiString) : { animated: undefined, id: emojiString, name: undefined }; |
64 |
new MessageEmbed() |
|
65 |
.setColor('#f14a60') |
if (!parsedEmoji) { |
66 |
.setDescription('No emoji found or not a guild based emoji!') |
await msg.reply({ |
67 |
] |
embeds: [ |
68 |
}); |
new MessageEmbed() |
69 |
|
.setColor('#f14a60') |
70 |
|
.setDescription('Invalid emoji!') |
71 |
|
] |
72 |
|
}); |
73 |
|
|
74 |
|
return; |
75 |
|
} |
76 |
|
|
77 |
|
await msg.reply({ |
78 |
|
embeds: [ |
79 |
|
new MessageEmbed() |
80 |
|
.setAuthor({ |
81 |
|
name: parsedEmoji.name ?? "Unknown Emoji", |
82 |
|
iconURL: `https://cdn.discordapp.com/emojis/${parsedEmoji.id}`, |
83 |
|
}) |
84 |
|
.setFields({ |
85 |
|
name: "Animated", |
86 |
|
value: parsedEmoji.animated !== undefined ? parsedEmoji.animated ? 'Yes' : 'No' : "*The system could not load enough information*", |
87 |
|
}, { |
88 |
|
name: "Download", |
89 |
|
value: `[Click Here](https://cdn.discordapp.com/emojis/${parsedEmoji.id})` |
90 |
|
}) |
91 |
|
.setThumbnail(`https://cdn.discordapp.com/emojis/${parsedEmoji.id}`) |
92 |
|
.setFooter({ |
93 |
|
text: `ID: ${parsedEmoji.id}` |
94 |
|
}) |
95 |
|
] |
96 |
|
}); |
97 |
|
} |
98 |
|
else { |
99 |
|
await msg.reply({ |
100 |
|
embeds: [ |
101 |
|
new MessageEmbed() |
102 |
|
.setColor('#f14a60') |
103 |
|
.setDescription('No emoji found or not a guild based emoji!') |
104 |
|
] |
105 |
|
}); |
106 |
|
} |
107 |
|
|
108 |
return; |
return; |
109 |
} |
} |
110 |
|
|
111 |
await msg.reply({ |
await msg.reply({ |
112 |
embeds: [ |
embeds: [ |
119 |
.addField('Name', emoji.name ?? '*No name set*') |
.addField('Name', emoji.name ?? '*No name set*') |
120 |
.addField('Identifier', emoji.identifier ?? '*No identifier set*') |
.addField('Identifier', emoji.identifier ?? '*No identifier set*') |
121 |
.addField('Available', emoji.available ? 'Yes' : 'No') |
.addField('Available', emoji.available ? 'Yes' : 'No') |
122 |
.addField('Created at', timeSince(emoji.createdAt.getTime())) |
.addField('Created', timeSince(emoji.createdAt.getTime())) |
123 |
.addField('Download', `[Click here](${emoji.url})`) |
.addField('Download', `[Click here](${emoji.url})`) |
124 |
.setImage(emoji.url) |
.setThumbnail(emoji.url) |
125 |
.setFooter({ |
.setFooter({ |
126 |
text: `ID: ${emoji.id}` |
text: `ID: ${emoji.id}` |
127 |
}) |
}) |