/[sudobot]/trunk/src/commands/settings/ConfigCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/settings/ConfigCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 382 by rakin, Mon Jul 29 17:29:40 2024 UTC revision 383 by rakin, Mon Jul 29 17:29:54 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, Message } from 'discord.js';  import { AutocompleteInteraction, CacheType, CommandInteraction, Message } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
# Line 6  import InteractionOptions from '../../ty Line 6  import InteractionOptions from '../../ty
6  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
7  import dot from 'dot-object';  import dot from 'dot-object';
8  import { fetchEmoji } from '../../utils/Emoji';  import { fetchEmoji } from '../../utils/Emoji';
9    import AutoCompleteOptions from '../../types/AutoCompleteOptions';
10    
11  export default class ConfigCommand extends BaseCommand {  export default class ConfigCommand extends BaseCommand {
12      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
13        configDotted: { [key: string]: string[] } = {};
14    
15      constructor() {      constructor() {
16          super('config', 'settings', []);          super('config', 'settings', []);
17            const config = DiscordClient.client.config.props;
18            
19            for (const guild in config) {
20                this.configDotted[guild] = Object.keys(dot.dot({...config[guild]}));
21            }
22        }
23    
24        async autoComplete(client: DiscordClient, interaction: AutocompleteInteraction<CacheType>, options: AutoCompleteOptions): Promise<void> {
25            const focused = interaction.options.getFocused(true);
26    
27            if (focused.name !== "key") {
28                return;
29            }
30    
31            if (focused.value === '') {
32                await interaction.respond(this.configDotted[interaction.guild!.id].slice(0, 25).map(key => ({
33                    name: key,
34                    value: key,
35                })));
36    
37                return;
38            }
39    
40            const response = [];
41    
42            for (const key of this.configDotted[interaction.guild!.id]) {
43                if (key.includes(focused.value)) {
44                    response.push({
45                        name: key,
46                        value: key
47                    });
48    
49                    if (response.length >= 25) {
50                        break;
51                    }
52                }
53            }
54    
55            await interaction.respond(response);
56      }      }
57    
58      async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {

Legend:
Removed from v.382  
changed lines
  Added in v.383

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26