/[sudobot]/branches/2.x/src/commands/automation/EmbedSendCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/automation/EmbedSendCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2885 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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     export default class EmbedSendCommand extends BaseCommand {
8     supportsInteractions: boolean = false;
9     supportsLegacy: boolean = false;
10     supportsContextMenu: boolean = false;
11    
12     constructor() {
13     super('embed__send', 'automation', []);
14     }
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     video: getString('video') ? {
47     url: getString('video')
48     } : undefined,
49     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     url: getString('url'),
61     });
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