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

Annotation of /trunk/src/commands/utils/DelsnippetCommand.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: 1981 byte(s)
chore: eslint autofix
1 rakin 344 import { CommandInteraction, Message } from 'discord.js';
2 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import InteractionOptions from '../../types/InteractionOptions';
6     import MessageEmbed from '../../client/MessageEmbed';
7     import { fetchEmoji } from '../../utils/Emoji';
8    
9     export default class DelsnippetCommand extends BaseCommand {
10     constructor() {
11     super('delsnippet', 'utils', []);
12     }
13    
14     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
15     if (!options.isInteraction && options.args[0] === undefined) {
16     await msg.reply({
17     embeds: [
18     new MessageEmbed()
19     .setColor('#f14a60')
20     .setDescription(`This command requires at least one argument.`)
21     ]
22     });
23    
24     return;
25     }
26    
27     let name: string;
28    
29     if (options.isInteraction) {
30     await (msg as CommandInteraction).deferReply();
31     name = <string> await options.options.getString('name');
32     }
33     else {
34     name = options.args[0];
35     }
36    
37     const snippet = client.snippetManager.get(msg.guild!.id, name);
38    
39     if (!snippet) {
40     await this.deferReply(msg, {
41     embeds: [
42     new MessageEmbed()
43     .setColor('#f14a60')
44     .setDescription("No snippet exists with that name.")
45     ]
46     });
47    
48     return;
49     }
50    
51     await client.snippetManager.delete(msg.guild!.id, name);
52     await client.snippetManager.write();
53    
54     await this.deferReply(msg, {
55     embeds: [
56     new MessageEmbed()
57     .setDescription((await fetchEmoji('check'))!.toString() + " Snippet deleted")
58     ]
59     });
60     }
61     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26