mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: better subcommand organiztion
This commit is contained in:
1 parent
2cabcc57f4
commit
23dd088466
15 files changed
+749
-867
No files matched your search
@@ -4,7 +4,7 @@ import {
|
||||
} from 'discord.js';
|
||||
import { PERIOD_NAMES } from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
||||
export type Period = 'period' | 'customperiod';
|
||||
|
||||
export default function addPeriodSubCommands(
|
||||
option: SlashCommandSubcommandGroupBuilder,
|
||||
@@ -14,25 +14,30 @@ export default function addPeriodSubCommands(
|
||||
) {
|
||||
return option
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('today').setDescription(PERIOD_NAMES.today)),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('30').setDescription(PERIOD_NAMES[30])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('60').setDescription(PERIOD_NAMES[60])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('90').setDescription(PERIOD_NAMES[90])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('career').setDescription(PERIOD_NAMES.career)),
|
||||
extra(
|
||||
option
|
||||
.setName('period' satisfies Period)
|
||||
.setDescription(PERIOD_NAMES.period)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('days')
|
||||
.setDescription('A preset period')
|
||||
.setChoices(
|
||||
{ name: 'Today', value: '1' },
|
||||
{ name: '30 days', value: '30' },
|
||||
{ name: '60 days', value: '60' },
|
||||
{ name: '90 days', value: '90' },
|
||||
{ name: 'Career', value: 'Infinity' },
|
||||
)
|
||||
.setRequired(true),
|
||||
),
|
||||
),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('custom')
|
||||
.setDescription(PERIOD_NAMES.custom)
|
||||
.setName('customperiod' satisfies Period)
|
||||
.setDescription(PERIOD_NAMES.customperiod)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('start')
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { tankopediaInfo } from '../blitz/tankopedia';
|
||||
import addPeriodSubCommands from './addPeriodSubCommands';
|
||||
import addTankChoices from './addTankChoices';
|
||||
import addUsernameChoices from './addUsernameChoices';
|
||||
|
||||
export default function addStatTypeSubCommandGroups(
|
||||
export default async function addStatTypeSubCommandGroups(
|
||||
option: SlashCommandBuilder,
|
||||
) {
|
||||
const awaitedTankopediaInfo = await tankopediaInfo;
|
||||
|
||||
return option
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
option.addStringOption(addUsernameChoices),
|
||||
)
|
||||
.setName('player')
|
||||
.setDescription("Player's statistics"),
|
||||
.setDescription('Player statistics'),
|
||||
)
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
@@ -21,6 +24,58 @@ export default function addStatTypeSubCommandGroups(
|
||||
.addStringOption(addUsernameChoices),
|
||||
)
|
||||
.setName('tank')
|
||||
.setDescription("Tank's statistics"),
|
||||
.setDescription('Tank statistics'),
|
||||
)
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
option
|
||||
.addStringOption((option) => {
|
||||
option
|
||||
.setName('nation')
|
||||
.setDescription('Nation')
|
||||
.addChoices(
|
||||
...Object.entries(awaitedTankopediaInfo.vehicle_nations).map(
|
||||
([type, name]) => ({ name, value: type }),
|
||||
),
|
||||
);
|
||||
|
||||
return option;
|
||||
})
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('tanktype')
|
||||
.setDescription('Type')
|
||||
.addChoices(
|
||||
...Object.entries(awaitedTankopediaInfo.vehicle_types).map(
|
||||
([type, name]) => ({
|
||||
name: name.replace(' Tank', ''),
|
||||
value: type,
|
||||
}),
|
||||
),
|
||||
)
|
||||
.setRequired(false),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('tier')
|
||||
.setDescription('Tier')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(10)
|
||||
.setRequired(false),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('treetype')
|
||||
.setDescription('Tech tree type')
|
||||
.addChoices(
|
||||
{ name: 'Tech Tree', value: 'techtree' },
|
||||
{ name: 'Premium', value: 'premium' },
|
||||
{ name: 'Collector', value: 'collector' },
|
||||
)
|
||||
.setRequired(false),
|
||||
),
|
||||
)
|
||||
.setName('tanks')
|
||||
.setDescription('Multiple tanks'),
|
||||
);
|
||||
}
|
||||
@@ -7,20 +7,16 @@ import { Period } from '../discord/addPeriodSubCommands';
|
||||
|
||||
export const PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's statistics",
|
||||
30: "30 days' statistics",
|
||||
60: "60 days' statistics",
|
||||
90: "90 days' statistics",
|
||||
period: "Set number of days' statistics",
|
||||
career: 'Career statistics',
|
||||
custom: 'Custom period',
|
||||
customperiod: 'Custom period',
|
||||
};
|
||||
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's evolution",
|
||||
30: "30 days' evolution",
|
||||
60: "60 days' evolution",
|
||||
90: "90 days' evolution",
|
||||
period: "Set number of days' evolution",
|
||||
career: 'Career evolution',
|
||||
custom: 'Custom period',
|
||||
customperiod: 'Custom period',
|
||||
};
|
||||
|
||||
export interface ResolvedPeriod {
|
||||
@@ -40,7 +36,7 @@ export default function resolvePeriodFromCommand(
|
||||
let end: number;
|
||||
const period = interaction.options.getSubcommand() as Period;
|
||||
|
||||
if (period === 'custom') {
|
||||
if (period === 'customperiod') {
|
||||
const startRaw = interaction.options.getInteger('start')!;
|
||||
const endRaw = interaction.options.getInteger('end')!;
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
|
||||
Reference in new issue
Block a user