diff --git a/src/core/discord/addFilterOptions.ts b/src/core/discord/addFilterOptions.ts index 683bd7bd2..5523016c9 100644 --- a/src/core/discord/addFilterOptions.ts +++ b/src/core/discord/addFilterOptions.ts @@ -1,76 +1,60 @@ -import { - SlashCommandBuilder, - SlashCommandSubcommandBuilder, - SlashCommandSubcommandGroupBuilder, -} from 'discord.js'; +import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from 'discord.js'; import { TREE_TYPE_NAMES, TreeType } from '../../components/Tanks'; -import { encyclopediaInfo } from '../blitz/encyclopediaInfo'; -import addPeriodSubCommands from './addPeriodSubCommands'; +import { EncyclopediaInfo } from '../blitz/encyclopediaInfo'; import addTankChoices from './addTankChoices'; import addTierChoices from './addTierChoices'; -export default async function addFilterOptions< - OptionType extends SlashCommandBuilder | SlashCommandSubcommandGroupBuilder, ->( - option: OptionType, - extra: ( - option: SlashCommandSubcommandBuilder, - ) => SlashCommandSubcommandBuilder = (option) => option, -): Promise { - const awaitedEncyclopediaInfo = await encyclopediaInfo; - - addPeriodSubCommands(option, (option) => { - extra(option); - - return option - .addStringOption((option) => - option - .setName('nation') - .setDescription('Nation') - .addChoices( - ...Object.entries(awaitedEncyclopediaInfo.vehicle_nations).map( - ([type, name]) => ({ name, value: type }), - ), - ) - .setRequired(false), - ) - .addStringOption((option) => addTierChoices(option).setRequired(false)) - .addStringOption((option) => - option - .setName('tank-type') - .setDescription('Tank type') - .addChoices( - ...Object.entries(awaitedEncyclopediaInfo.vehicle_types).map( - ([type, name]) => ({ - name: name.replace(' Tank', ''), - value: type, - }), - ), - ) - .setRequired(false), - ) - .addStringOption((option) => - option - .setName('tree-type') - .setDescription('Tech tree type') - .addChoices( - { - name: TREE_TYPE_NAMES['researchable'], - value: 'researchable' satisfies TreeType, - }, - { - name: TREE_TYPE_NAMES.premium, - value: 'premium' satisfies TreeType, - }, - { - name: TREE_TYPE_NAMES.collector, - value: 'collector' satisfies TreeType, - }, - ) - .setRequired(false), - ) - .addStringOption((option) => addTankChoices(option).setRequired(false)); - }); - - return option; +export function addFilterOptions< + Option extends SlashCommandBuilder | SlashCommandSubcommandBuilder, +>(option: Option, encyclopediaInfo: EncyclopediaInfo) { + return option + .addStringOption((option) => + option + .setName('nation') + .setDescription('Nation') + .addChoices( + ...Object.entries(encyclopediaInfo.vehicle_nations).map( + ([type, name]) => ({ name, value: type }), + ), + ) + .setRequired(false), + ) + .addStringOption((option) => addTierChoices(option).setRequired(false)) + .addStringOption((option) => + option + .setName('tank-type') + .setDescription('Tank type') + .addChoices( + ...Object.entries(encyclopediaInfo.vehicle_types).map( + ([type, name]) => ({ + name: name.replace(' Tank', ''), + value: type, + }), + ), + ) + .setRequired(false), + ) + .addStringOption((option) => + option + .setName('tree-type') + .setDescription('Tech tree type') + .addChoices( + { + name: TREE_TYPE_NAMES['researchable'], + value: 'researchable' satisfies TreeType, + }, + { + name: TREE_TYPE_NAMES.premium, + value: 'premium' satisfies TreeType, + }, + { + name: TREE_TYPE_NAMES.collector, + value: 'collector' satisfies TreeType, + }, + ) + .setRequired(false), + ) + .addStringOption((option) => + addTankChoices(option).setRequired(false), + ) as Option; }