1 |
import { ColorResolvable, CommandInteraction, Message, Util } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import InteractionOptions from '../../types/InteractionOptions'; |
5 |
import MessageEmbed from '../../client/MessageEmbed'; |
6 |
import CommandOptions from '../../types/CommandOptions'; |
7 |
import { emoji, fetchEmoji } from '../../utils/Emoji'; |
8 |
|
9 |
export default class EmbedBuildCommand extends BaseCommand { |
10 |
supportsInteractions: boolean = false; |
11 |
supportsLegacy: boolean = false; |
12 |
|
13 |
constructor() { |
14 |
super('embed__build', 'automation', []); |
15 |
} |
16 |
|
17 |
async run(client: DiscordClient, message: CommandInteraction | Message, options: InteractionOptions | CommandOptions) { |
18 |
if (!options.isInteraction && options.args[0] === undefined) { |
19 |
await message.reply(`${emoji('error')} No embed schema provided.`); |
20 |
return; |
21 |
} |
22 |
|
23 |
try { |
24 |
const embedData = JSON.parse((options.isInteraction ? options.options.getString('json_schema')! : options.args.join(' ')).replace(/^embed\:/, '')); |
25 |
|
26 |
if (!embedData) { |
27 |
throw new Error('Parse Error'); |
28 |
} |
29 |
|
30 |
try { |
31 |
const embed = new MessageEmbed(embedData); |
32 |
|
33 |
if (embedData.color) { |
34 |
try { |
35 |
embed.setColor(embedData.color); |
36 |
} |
37 |
catch (e) { |
38 |
console.log(e); |
39 |
} |
40 |
} |
41 |
|
42 |
await message.channel?.send({ |
43 |
embeds: [embed] |
44 |
}); |
45 |
|
46 |
if (message instanceof CommandInteraction) |
47 |
await message.reply({ content: 'Message sent.', ephemeral: true }); |
48 |
else |
49 |
message.react((await fetchEmoji('check'))!).catch(console.error); |
50 |
} |
51 |
catch (e) { |
52 |
console.log(e); |
53 |
message.reply({ content: 'Invalid options given.', ephemeral: true }); |
54 |
} |
55 |
} |
56 |
catch (e) { |
57 |
console.log(e); |
58 |
message.reply({ content: 'Invalid embed JSON schema given.', ephemeral: true }); |
59 |
return; |
60 |
} |
61 |
} |
62 |
} |