diff --git a/package.json b/package.json index 9f2ed30ea..dc2934a1b 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "main": "src/index.ts", "type": "module", "scripts": { - "dev": "yarn build --dev && yarn start", + "dev": "yarn build:raw --dev && yarn start", "start": "node --enable-source-maps --trace-warnings dist/index.cjs", "zip": "zip -r dist.zip dist", - "build": "yarn lint && node scripts/build", + "build:raw": "node scripts/build", + "build": "yarn lint && yarn build:raw", "lint": "tsc" }, "license": "MIT", diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index 49939ae6f..5a6fdcb09 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -15,12 +15,11 @@ import { tankopedia } from '../core/blitz/tankopedia.js'; import getTankHistories from '../core/blitzstars/getTankHistories.js'; import cmdName from '../core/interaction/cmdName.js'; import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js'; -import addPeriodSubCommands, { +import { Period, RELATIVE_PERIOD_NAMES, } from '../core/options/addPeriodSubCommands.js'; -import addTankChoices from '../core/options/addTankChoices.js'; -import addUsernameOption from '../core/options/addUsernameOption.js'; +import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js'; import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -32,25 +31,11 @@ export default { inDevelopment: true, inPublic: true, - command: new SlashCommandBuilder() - .setName(cmdName('evolution')) - .setDescription('Evolution of statistics') - .addSubcommandGroup((option) => - addPeriodSubCommands(option, (option) => - option.addStringOption(addUsernameOption), - ) - .setName('player') - .setDescription("Player's statistics"), - ) - .addSubcommandGroup((option) => - addPeriodSubCommands(option, (option) => - option - .addStringOption(addTankChoices) - .addStringOption(addUsernameOption), - ) - .setName('tank') - .setDescription("Tank's statistics"), - ), + command: addStatsSubCommandGroups( + new SlashCommandBuilder() + .setName(cmdName('evolution')) + .setDescription('Evolution of statistics'), + ), async execute(interaction) { const commandGroup = interaction.options.getSubcommandGroup()!; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 8d7f11fc6..9a65c019c 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -18,9 +18,7 @@ import { Tier, tankopedia } from '../core/blitz/tankopedia.js'; import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js'; import cmdName from '../core/interaction/cmdName.js'; -import addPeriodSubCommands from '../core/options/addPeriodSubCommands.js'; -import addTankChoices from '../core/options/addTankChoices.js'; -import addUsernameOption from '../core/options/addUsernameOption.js'; +import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js'; import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -36,26 +34,11 @@ export default { inDevelopment: true, inPublic: true, - command: new SlashCommandBuilder() - // TODO: embed cmdName into interaction create - .setName(cmdName('stats')) - .setDescription('In-game statistics') - .addSubcommandGroup((option) => - addPeriodSubCommands(option, (option) => - option.addStringOption(addUsernameOption), - ) - .setName('player') - .setDescription("Player's statistics"), - ) - .addSubcommandGroup((option) => - addPeriodSubCommands(option, (option) => - option - .addStringOption(addTankChoices) - .addStringOption(addUsernameOption), - ) - .setName('tank') - .setDescription("Tank's statistics"), - ), + command: addStatsSubCommandGroups( + new SlashCommandBuilder() + .setName(cmdName('stats')) + .setDescription('In-game statistics'), + ), async execute(interaction) { const commandGroup = interaction.options.getSubcommandGroup()!; @@ -81,11 +64,7 @@ export default { image = tankopedia[tankId].images.normal; } - const { - statsName, - start, - end, - } = getPeriodDataFromSubcommand(interaction); + const { statsName, start, end } = getPeriodDataFromSubcommand(interaction); const tankStats = await getTankStatsOverTime(server, id, start, end); let stats: AllStats; diff --git a/src/core/options/addStatsSubCommandGroups.ts b/src/core/options/addStatsSubCommandGroups.ts new file mode 100644 index 000000000..f24315784 --- /dev/null +++ b/src/core/options/addStatsSubCommandGroups.ts @@ -0,0 +1,24 @@ +import { SlashCommandBuilder } from 'discord.js'; +import addPeriodSubCommands from './addPeriodSubCommands.js'; +import addTankChoices from './addTankChoices.js'; +import addUsernameOption from './addUsernameOption.js'; + +export default function addStatsSubCommandGroups(option: SlashCommandBuilder) { + return option + .addSubcommandGroup((option) => + addPeriodSubCommands(option, (option) => + option.addStringOption(addUsernameOption), + ) + .setName('player') + .setDescription("Player's statistics"), + ) + .addSubcommandGroup((option) => + addPeriodSubCommands(option, (option) => + option + .addStringOption(addTankChoices) + .addStringOption(addUsernameOption), + ) + .setName('tank') + .setDescription("Tank's statistics"), + ); +}