/[sudobot]/branches/2.x/src/commands/settings/ConfigCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/settings/ConfigCommand.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: 2184 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import { CommandInteraction, GuildMember, Interaction, Message } from 'discord.js';
2     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 dot from 'dot-object';
8     import { fetchEmoji } from '../../utils/Emoji';
9    
10     export default class ConfigCommand extends BaseCommand {
11     supportsInteractions: boolean = true;
12    
13     constructor() {
14     super('config', 'settings', []);
15     }
16    
17     async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
18     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
19     await message.reply({
20     embeds: [
21     new MessageEmbed()
22     .setColor('#f14a60')
23     .setDescription(`This command requires at least one argument.`)
24     ]
25     });
26    
27     return;
28     }
29    
30     const keyMap = options.isInteraction ? options.options.getString('key') : options.args[0];
31     const value = options.isInteraction ? options.options.getString('value') : options.args[1];
32    
33     if (keyMap && !value) {
34     const val = dot.pick(keyMap, client.config.props[message.guild!.id]);
35    
36     await message.reply({
37     content: val === undefined ? `${await fetchEmoji('error')} The given configuration key does not exist.` : (typeof val === 'object' ? "```json" + JSON.stringify(val, null, 2) + "```" : (val + ''))
38     });
39     }
40     else if (keyMap && value) {
41     if (dot.pick(keyMap, client.config.props[message.guild!.id]) === undefined) {
42     await message.reply({ content: `${await fetchEmoji('error')} The given configuration key does not exist.` });
43     return;
44     }
45    
46     dot.set(keyMap, value, client.config.props[message.guild!.id]);
47     await message.reply({ content: `${await fetchEmoji('check')} Configuration updated.` });
48     }
49     }
50     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26