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

Contents of /trunk/src/commands/automation/EmbedSchemaCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2621 byte(s)
chore: eslint autofix
1 import { ColorResolvable, CommandInteraction, Util } from 'discord.js';
2 import BaseCommand from '../../utils/structures/BaseCommand';
3 import DiscordClient from '../../client/Client';
4 import InteractionOptions from '../../types/InteractionOptions';
5
6 export default class EmbedSchemaCommand extends BaseCommand {
7 supportsInteractions: boolean = false;
8 supportsLegacy: boolean = false;
9 supportsContextMenu: boolean = false;
10
11 constructor() {
12 super('embed__schema', 'automation', []);
13 }
14
15 async run(client: DiscordClient, interaction: CommandInteraction, options: InteractionOptions) {
16 const getString = (field: string): string | undefined => {
17 return options.options.getString(field) ?? undefined;
18 };
19
20 const author = {
21 name: getString('author_name'),
22 iconURL: getString('author_iconurl'),
23 };
24
25 const footer = {
26 text: getString('footer_text'),
27 iconURL: getString('footer_iconurl'),
28 };
29
30 if (getString('color') && (!Util.resolveColor(getString('color') as ColorResolvable) || Util.resolveColor(getString('color') as ColorResolvable) === NaN)) {
31 await interaction.reply({ content: "Invalid color given.", ephemeral: true });
32 return;
33 }
34
35 const embed = {
36 author: author.name ? author : undefined,
37 title: getString('title'),
38 description: getString('description'),
39 thumbnail: getString('thumbnail') ? {
40 url: getString('thumbnail')
41 } : undefined,
42 image: getString('image') ? {
43 url: getString('image')
44 } : undefined,
45 video: getString('video') ? {
46 url: getString('video')
47 } : undefined,
48 footer: footer.text ? footer : undefined,
49 color: (getString('color') ?? '#007bff') as ColorResolvable,
50 timestamp: getString('timestamp') ? (getString('timestamp') === 'current' ? new Date() : new Date(getString('timestamp')!)) : undefined,
51 fields: getString('fields') ? getString('fields')!.trim().split(',').map(fieldData => {
52 const [name, value] = fieldData.trim().split(':');
53
54 return {
55 name: name.trim(),
56 value: value.trim(),
57 };
58 }) : [],
59 url: getString('url'),
60 };
61
62 await interaction.reply({ content: `**Embed Schema**:\n\`\`\`\nembed:${JSON.stringify(embed)}\n\`\`\`\nYou can now use this schema to build embeds.` });
63 }
64 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26