feat: extracted sub command groups

This commit is contained in:
TresAbhi committed 2023-06-21 01:57:27 +00:00
1 parent 70145abe86
commit 3e8e198c88
4 files changed
+41 -52

No files matched your search

+3 -2
View File
@@ -5,10 +5,11 @@
"main": "src/index.ts", "main": "src/index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "yarn build --dev && yarn start", "dev": "yarn build:raw --dev && yarn start",
"start": "node --enable-source-maps --trace-warnings dist/index.cjs", "start": "node --enable-source-maps --trace-warnings dist/index.cjs",
"zip": "zip -r dist.zip dist", "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" "lint": "tsc"
}, },
"license": "MIT", "license": "MIT",
+7 -22
View File
@@ -15,12 +15,11 @@ import { tankopedia } from '../core/blitz/tankopedia.js';
import getTankHistories from '../core/blitzstars/getTankHistories.js'; import getTankHistories from '../core/blitzstars/getTankHistories.js';
import cmdName from '../core/interaction/cmdName.js'; import cmdName from '../core/interaction/cmdName.js';
import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js'; import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js';
import addPeriodSubCommands, { import {
Period, Period,
RELATIVE_PERIOD_NAMES, RELATIVE_PERIOD_NAMES,
} from '../core/options/addPeriodSubCommands.js'; } from '../core/options/addPeriodSubCommands.js';
import addTankChoices from '../core/options/addTankChoices.js'; import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js'; import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js'; import { CommandRegistry } from '../events/interactionCreate.js';
@@ -32,25 +31,11 @@ export default {
inDevelopment: true, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: addStatsSubCommandGroups(
.setName(cmdName('evolution')) new SlashCommandBuilder()
.setDescription('Evolution of statistics') .setName(cmdName('evolution'))
.addSubcommandGroup((option) => .setDescription('Evolution of statistics'),
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"),
),
async execute(interaction) { async execute(interaction) {
const commandGroup = interaction.options.getSubcommandGroup()!; const commandGroup = interaction.options.getSubcommandGroup()!;
+7 -28
View File
@@ -18,9 +18,7 @@ import { Tier, tankopedia } from '../core/blitz/tankopedia.js';
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js'; import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
import { tankAverages } from '../core/blitzstars/tankAverages.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js';
import cmdName from '../core/interaction/cmdName.js'; import cmdName from '../core/interaction/cmdName.js';
import addPeriodSubCommands from '../core/options/addPeriodSubCommands.js'; import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
import addTankChoices from '../core/options/addTankChoices.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js'; import getPeriodDataFromSubcommand from '../core/options/getPeriodDataFromSubcommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js'; import { CommandRegistry } from '../events/interactionCreate.js';
@@ -36,26 +34,11 @@ export default {
inDevelopment: true, inDevelopment: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: addStatsSubCommandGroups(
// TODO: embed cmdName into interaction create new SlashCommandBuilder()
.setName(cmdName('stats')) .setName(cmdName('stats'))
.setDescription('In-game statistics') .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"),
),
async execute(interaction) { async execute(interaction) {
const commandGroup = interaction.options.getSubcommandGroup()!; const commandGroup = interaction.options.getSubcommandGroup()!;
@@ -81,11 +64,7 @@ export default {
image = tankopedia[tankId].images.normal; image = tankopedia[tankId].images.normal;
} }
const { const { statsName, start, end } = getPeriodDataFromSubcommand(interaction);
statsName,
start,
end,
} = getPeriodDataFromSubcommand(interaction);
const tankStats = await getTankStatsOverTime(server, id, start, end); const tankStats = await getTankStatsOverTime(server, id, start, end);
let stats: AllStats; let stats: AllStats;
@@ -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"),
);
}