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
|
2023-07-05 02:09:36 +00:00
|
|
|
? 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-07-05 02:09:36 +00:00
|
|
|
({
|
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-07-05 02:09:36 +00:00
|
|
|
),
|
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
|
|
|
}
|