Files
blitzkit/src/core/discord/autocompleteTanks.ts
T

33 lines
968 B
TypeScript
Raw Normal View History

2023-05-13 21:42:40 +00:00
import {
ApplicationCommandOptionChoiceData,
AutocompleteInteraction,
CacheType,
} from 'discord.js';
import { go } from 'fuzzysort';
2023-08-10 01:46:39 +00:00
import { TANKS, TANK_NAMES_DIACRITICS } from '../blitz/tankopedia';
2023-05-13 21:42:40 +00:00
2023-06-27 02:22:28 +00:00
export default async function autocompleteTanks(
2023-05-13 21:42:40 +00:00
interaction: AutocompleteInteraction<CacheType>,
) {
2023-05-14 17:13:42 +00:00
const focusedOption = interaction.options.getFocused(true);
if (focusedOption.name !== 'tank') return;
2023-05-13 21:42:40 +00:00
await interaction.respond(
2023-05-14 17:13:42 +00:00
focusedOption.value
? await Promise.all(
2023-08-10 01:46:39 +00:00
go(focusedOption.value, await TANK_NAMES_DIACRITICS, {
keys: ['combined'],
2023-07-11 19:54:57 +00:00
limit: 10,
}).map(
2023-08-10 01:46:39 +00:00
async (item, index) =>
({
2023-08-10 01:46:39 +00:00
name: item.obj.original,
value: `${(await TANKS)[index].tank_id}`,
2023-07-11 19:54:57 +00:00
}) satisfies ApplicationCommandOptionChoiceData<string>,
),
2023-05-13 21:42:40 +00:00
)
: [],
);
2023-05-14 17:13:42 +00:00
console.log(`Tanks autocomplete for ${focusedOption.value}`);
2023-05-13 21:42:40 +00:00
}