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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (hide annotations)
Mon Jul 29 17:29:12 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2885 byte(s)
feat: make subcommands of embed command (#57)
1 rakin 248 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    
7 rakin 249 export default class EmbedSendCommand extends BaseCommand {
8     supportsInteractions: boolean = false;
9 rakin 248 supportsLegacy: boolean = false;
10 rakin 249 supportsContextMenu: boolean = false;
11 rakin 248
12     constructor() {
13 rakin 249 super('embed__send', 'automation', []);
14 rakin 248 }
15    
16     async run(client: DiscordClient, interaction: CommandInteraction, options: InteractionOptions) {
17     const getString = (field: string): string | undefined => {
18     return options.options.getString(field) ?? undefined;
19     };
20    
21     const author = {
22     name: getString('author_name'),
23     iconURL: getString('author_iconurl'),
24     };
25    
26     const footer = {
27     text: getString('footer_text'),
28     iconURL: getString('footer_iconurl'),
29     };
30    
31     if (getString('color') && (!Util.resolveColor(getString('color') as ColorResolvable) || Util.resolveColor(getString('color') as ColorResolvable) === NaN)) {
32     await interaction.reply({ content: "Invalid color given.", ephemeral: true });
33     return;
34     }
35    
36     const embed = new MessageEmbed({
37     author: author.name ? author : undefined,
38     title: getString('title'),
39     description: getString('description'),
40     thumbnail: getString('thumbnail') ? {
41     url: getString('thumbnail')
42     } : undefined,
43     image: getString('image') ? {
44     url: getString('image')
45     } : undefined,
46 rakin 249 video: getString('video') ? {
47     url: getString('video')
48     } : undefined,
49 rakin 248 footer: footer.text ? footer : undefined,
50     color: (getString('color') ?? '#007bff') as ColorResolvable,
51     timestamp: getString('timestamp') ? (getString('timestamp') === 'current' ? new Date() : new Date(getString('timestamp')!)) : undefined,
52     fields: getString('fields') ? getString('fields')!.trim().split(',').map(fieldData => {
53     const [name, value] = fieldData.trim().split(':');
54    
55     return {
56     name: name.trim(),
57     value: value.trim(),
58     };
59     }) : [],
60 rakin 249 url: getString('url'),
61 rakin 248 });
62    
63     try {
64     await interaction.channel?.send({
65     embeds: [embed]
66     });
67    
68     await interaction.reply({ content: 'Message sent.', ephemeral: true });
69     }
70     catch (e) {
71     console.log(e);
72     interaction.reply({ content: 'Invalid options given.', ephemeral: true });
73     }
74     }
75     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26