mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
34 lines
937 B
TypeScript
34 lines
937 B
TypeScript
import {
|
|
ApplicationCommandOptionChoiceData,
|
|
AutocompleteInteraction,
|
|
CacheType,
|
|
} from 'discord.js';
|
|
import { go } from 'fuzzysort';
|
|
import { TANK_NAMES_DIACRITICS } from '../blitz/tankopedia';
|
|
|
|
export default async function autocompleteTanks(
|
|
interaction: AutocompleteInteraction<CacheType>,
|
|
) {
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
if (focusedOption.name !== 'tank') return;
|
|
|
|
await interaction.respond(
|
|
focusedOption.value
|
|
? await Promise.all(
|
|
go(focusedOption.value, await TANK_NAMES_DIACRITICS, {
|
|
keys: ['combined'],
|
|
limit: 10,
|
|
}).map(
|
|
async (item) =>
|
|
({
|
|
name: item.obj.original,
|
|
value: `${item.obj.id}`,
|
|
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
|
),
|
|
)
|
|
: [],
|
|
);
|
|
|
|
console.log(`Tanks autocomplete for ${focusedOption.value}`);
|
|
}
|