/[sudobot]/trunk/src/commands/utils/SnippetCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/utils/SnippetCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (hide annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 2191 byte(s)
chore: eslint autofix
1 rakin 344 import { CommandInteraction, FileOptions } from 'discord.js';
2 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import InteractionOptions from '../../types/InteractionOptions';
5     import path from 'path';
6    
7     export default class AddsnippetCommand extends BaseCommand {
8     supportsInteractions: boolean = true;
9     supportsLegacy: boolean = false;
10    
11     constructor() {
12     super('snippet', 'utils', []);
13     }
14    
15     async run(client: DiscordClient, msg: CommandInteraction, options: InteractionOptions) {
16     if (options.options.getSubcommand(true) === 'get') {
17 rakin 255 const snippet = await client.snippetManager.getParsed(msg.guild!.id, options.options.getString('name')!);
18 rakin 51
19     if (!snippet) {
20     await msg.reply({
21     content: ":x: No snippet found with that name.",
22     ephemeral: true
23     });
24    
25     return;
26     }
27    
28 rakin 257 try {
29     await msg.reply({
30     content: snippet.content.trim() === '' ? undefined : snippet.content,
31     files: snippet.files.map(name => {
32     return {
33     name,
34     attachment: path.resolve(__dirname, '../../../storage', name)
35     } as FileOptions
36     }),
37     embeds: snippet.embeds
38     });
39     }
40     catch (e) {
41     console.log(e);
42     await msg.reply({ content: 'Looks like that snippet is corrupted. Maybe invalid embed schema?', ephemeral: true });
43     }
44 rakin 51 }
45    
46     let cmdName = '';
47    
48     if (options.options.getSubcommand(true) === 'create')
49     cmdName = 'addsnippet';
50     else if (options.options.getSubcommand(true) === 'delete')
51     cmdName = 'delsnippet';
52     else if (options.options.getSubcommand(true) === 'rename')
53     cmdName = 'mvsnippet';
54    
55     const command = await client.commands.get(cmdName);
56    
57     if (command) {
58     return await command.run(client, msg, options);
59     }
60     }
61     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26