/[sudobot]/trunk/src/commands/automation/EmbedBuildCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/automation/EmbedBuildCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 251 - (hide annotations)
Mon Jul 29 17:29:13 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1968 byte(s)
feat: create embeds from JSON schema (#57)
1 rakin 251 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(' '));
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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26