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 |
|
12 |
constructor() { |
13 |
super('embed__build', 'automation', []); |
14 |
} |
15 |
|
16 |
async run(client: DiscordClient, message: CommandInteraction | Message, options: InteractionOptions | CommandOptions) { |
17 |
if (!options.isInteraction && options.args[0] === undefined) { |
18 |
await message.reply(`${emoji('error')} No embed schema provided.`); |
19 |
return; |
20 |
} |
21 |
|
22 |
try { |
23 |
const embedData = JSON.parse((options.isInteraction ? options.options.getString('json_schema')! : options.args.join(' ')).replace(/^embed\:/, '')); |
24 |
|
25 |
if (!embedData) { |
26 |
throw new Error('Parse Error'); |
27 |
} |
28 |
|
29 |
try { |
30 |
const embed = new MessageEmbed(embedData); |
31 |
|
32 |
await message.channel?.send({ |
33 |
embeds: [embed] |
34 |
}); |
35 |
|
36 |
if (message instanceof CommandInteraction) |
37 |
await message.reply({ content: 'Message sent.', ephemeral: true }); |
38 |
else |
39 |
message.react((await fetchEmoji('check'))!).catch(console.error); |
40 |
} |
41 |
catch (e) { |
42 |
console.log(e); |
43 |
message.reply({ content: 'Invalid options given.', ephemeral: true }); |
44 |
} |
45 |
} |
46 |
catch (e) { |
47 |
console.log(e); |
48 |
message.reply({ content: 'Invalid embed JSON schema given.', ephemeral: true }); |
49 |
return; |
50 |
} |
51 |
} |
52 |
} |