diff options
Diffstat (limited to 'src/commands/info/help.ts')
-rw-r--r-- | src/commands/info/help.ts | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index e1e9844..c4abf78 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,5 +1,6 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; +import { AutocompleteInteraction, MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; +import Fuse from 'fuse.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; export default class HelpCommand extends BushCommand { @@ -19,7 +20,8 @@ export default class HelpCommand extends BushCommand { prompt: 'What command do you need help with?', retry: '{error} Choose a valid command to find help for.', slashType: 'STRING', - optional: true + optional: true, + autocomplete: true }, { id: 'showHidden', @@ -49,7 +51,7 @@ export default class HelpCommand extends BushCommand { const isSuperUser = client.isSuperUser(message.author); const command = args.command ? typeof args.command === 'string' - ? (client.commandHandler.findCommand(args.command) as BushCommand) ?? null + ? client.commandHandler.findCommand(args.command) ?? null : args.command : null; if (!isOwner) args.showHidden = false; @@ -150,4 +152,24 @@ export default class HelpCommand extends BushCommand { return row; } + + public override autocomplete(interaction: AutocompleteInteraction) { + const aliases = this.handler.modules.map((module) => module.aliases).flat(); + + const fuzzy = new Fuse(aliases, { + threshold: 0.5, + isCaseSensitive: false, + findAllMatches: true + }).search(interaction.options.getFocused().toString()); + + const res = fuzzy.slice(0, fuzzy.length >= 25 ? 25 : undefined).map((v) => ({ name: v.item, value: v.item })); + + const startingCommands = [ + ...this.handler.modules.filter((command) => !command.ownerOnly && !command.hidden && !command.pseudo).keys() + ] + .slice(0, 25) + .map((v) => ({ name: v, value: v })); + + void interaction.respond(res.length ? res : startingCommands); + } } |