aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/capes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/moulberry-bush/capes.ts')
-rw-r--r--src/commands/moulberry-bush/capes.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts
index 4bdb360..ab6910a 100644
--- a/src/commands/moulberry-bush/capes.ts
+++ b/src/commands/moulberry-bush/capes.ts
@@ -1,5 +1,6 @@
import { BushCommand, ButtonPaginator, DeleteButton, type BushMessage, type OptionalArgType } from '#lib';
-import { type MessageEmbedOptions } from 'discord.js';
+import { AutocompleteInteraction, type MessageEmbedOptions } from 'discord.js';
+import Fuse from 'fuse.js';
import got from 'got';
export default class CapesCommand extends BushCommand {
@@ -18,8 +19,8 @@ export default class CapesCommand extends BushCommand {
prompt: 'What cape would you like to see?',
retry: '{error} Choose a cape to see.',
optional: true,
- slashType: 'STRING'
- // choices: client.consts.mappings.capes.map((v) => ({ name: v.name, value: v.name }))
+ slashType: 'STRING',
+ autocomplete: true
}
],
slash: true,
@@ -96,6 +97,20 @@ export default class CapesCommand extends BushCommand {
description: cape.purchasable ? ':money_with_wings: **purchasable** :money_with_wings:' : undefined
};
}
+
+ public override autocomplete(interaction: AutocompleteInteraction) {
+ const capes = client.consts.mappings.capes.map((v) => v.name);
+
+ const fuzzy = new Fuse(capes, {
+ 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 }));
+
+ void interaction.respond(res);
+ }
}
export interface GithubFile {