aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-01-01 08:53:23 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-01-01 08:53:23 -0500
commite0ae0639d0b36c3cfd4065f791b95a32c1d7ea64 (patch)
tree46547b51ad50b0a7a73fbc848ad643f8736399ae /src/commands/info
parentcbb68773614e44eb246e4cf2ff0d64d3e90f620f (diff)
downloadtanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.gz
tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.bz2
tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.zip
added autocomplete to a few commands and performed some fixes
Diffstat (limited to 'src/commands/info')
-rw-r--r--src/commands/info/color.ts2
-rw-r--r--src/commands/info/help.ts28
2 files changed, 26 insertions, 4 deletions
diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts
index 7f3e593..2b8ba9c 100644
--- a/src/commands/info/color.ts
+++ b/src/commands/info/color.ts
@@ -52,7 +52,7 @@ export default class ColorCommand extends BushCommand {
args: { color: string | ArgType<'role'> | ArgType<'member'> }
) {
const _color = message.util.isSlashMessage(message)
- ? ((await util.arg.cast(util.arg.union(isValidTinyColor as any, 'role', 'member'), message, args.color as string)) as
+ ? ((await util.arg.cast(util.arg.union(isValidTinyColor, 'role', 'member'), message, args.color as string)) as
| string
| BushRole
| BushGuildMember)
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);
+ }
}