mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: better and unified tier selection
This commit is contained in:
1 parent
caa7bb8a65
commit
364f97332b
6 files changed
+59
-27
No files matched your search
@@ -62,6 +62,8 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
)
|
)
|
||||||
)[player.id];
|
)[player.id];
|
||||||
|
|
||||||
|
const tierOption = interaction.options.getString('tier');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
await fullStats(
|
await fullStats(
|
||||||
commandGroup,
|
commandGroup,
|
||||||
@@ -74,7 +76,7 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
'tank-type':
|
'tank-type':
|
||||||
interaction.options.getString('tank-type') ?? undefined,
|
interaction.options.getString('tank-type') ?? undefined,
|
||||||
nation: interaction.options.getString('nation') ?? undefined,
|
nation: interaction.options.getString('nation') ?? undefined,
|
||||||
tier: interaction.options.getInteger('tier') ?? undefined,
|
tier: tierOption ? parseInt(tierOption) : undefined,
|
||||||
'tree-type': (interaction.options.getString('tree-type') ??
|
'tree-type': (interaction.options.getString('tree-type') ??
|
||||||
undefined) as TreeTypeString | undefined,
|
undefined) as TreeTypeString | undefined,
|
||||||
} satisfies Partial<MultiTankFilters>)
|
} satisfies Partial<MultiTankFilters>)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
tankopedia,
|
tankopedia,
|
||||||
tankopediaInfo,
|
tankopediaInfo,
|
||||||
} from '../core/blitz/tankopedia';
|
} from '../core/blitz/tankopedia';
|
||||||
|
import addTierChoices from '../core/discord/addTierChoices';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
@@ -52,24 +53,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName('owned-tanks')
|
.setName('owned-tanks')
|
||||||
.setDescription("Shows a player's owned tanks")
|
.setDescription("Shows a player's owned tanks")
|
||||||
.addStringOption((option) =>
|
.addStringOption(addTierChoices)
|
||||||
option
|
|
||||||
.setName('tier')
|
|
||||||
.setDescription('The tier you want to see')
|
|
||||||
.setChoices(
|
|
||||||
{ name: 'Tier I (1)', value: '1' },
|
|
||||||
{ name: 'Tier II (2)', value: '2' },
|
|
||||||
{ name: 'Tier III (3)', value: '3' },
|
|
||||||
{ name: 'Tier IV (4)', value: '4' },
|
|
||||||
{ name: 'Tier V (5)', value: '5' },
|
|
||||||
{ name: 'Tier VI (6)', value: '6' },
|
|
||||||
{ name: 'Tier VII (7)', value: '7' },
|
|
||||||
{ name: 'Tier VIII (8)', value: '8' },
|
|
||||||
{ name: 'Tier IX (9)', value: '9' },
|
|
||||||
{ name: 'Tier X (10)', value: '10' },
|
|
||||||
)
|
|
||||||
.setRequired(true),
|
|
||||||
)
|
|
||||||
.addStringOption(addUsernameChoices),
|
.addStringOption(addUsernameChoices),
|
||||||
|
|
||||||
async handler(interaction) {
|
async handler(interaction) {
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
)
|
)
|
||||||
)[player.id];
|
)[player.id];
|
||||||
|
|
||||||
|
const tierOption = interaction.options.getString('tier');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
await stats(
|
await stats(
|
||||||
commandGroup,
|
commandGroup,
|
||||||
@@ -72,7 +74,7 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
'tank-type':
|
'tank-type':
|
||||||
interaction.options.getString('tank-type') ?? undefined,
|
interaction.options.getString('tank-type') ?? undefined,
|
||||||
nation: interaction.options.getString('nation') ?? undefined,
|
nation: interaction.options.getString('nation') ?? undefined,
|
||||||
tier: interaction.options.getInteger('tier') ?? undefined,
|
tier: tierOption ? parseInt(tierOption) : undefined,
|
||||||
'tree-type': (interaction.options.getString('tree-type') ??
|
'tree-type': (interaction.options.getString('tree-type') ??
|
||||||
undefined) as TreeTypeString | undefined,
|
undefined) as TreeTypeString | undefined,
|
||||||
} satisfies Partial<MultiTankFilters>)
|
} satisfies Partial<MultiTankFilters>)
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Thanks, August!
|
||||||
|
* https://stackoverflow.com/a/41358305/12294756
|
||||||
|
*/
|
||||||
|
const ROMAN = {
|
||||||
|
M: 1000,
|
||||||
|
CM: 900,
|
||||||
|
D: 500,
|
||||||
|
CD: 400,
|
||||||
|
C: 100,
|
||||||
|
XC: 90,
|
||||||
|
L: 50,
|
||||||
|
XL: 40,
|
||||||
|
X: 10,
|
||||||
|
IX: 9,
|
||||||
|
V: 5,
|
||||||
|
IV: 4,
|
||||||
|
I: 1,
|
||||||
|
};
|
||||||
|
const ROMAN_KEYS = Object.keys(ROMAN) as (keyof typeof ROMAN)[];
|
||||||
|
|
||||||
|
export default function numberToRomanNumeral(value: number) {
|
||||||
|
let string = '';
|
||||||
|
|
||||||
|
ROMAN_KEYS.forEach((index) => {
|
||||||
|
const part = Math.floor(value / ROMAN[index]);
|
||||||
|
value -= part * ROMAN[index];
|
||||||
|
string += index.repeat(part);
|
||||||
|
});
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import { StatType } from '../../renderers/stats';
|
|||||||
import { tankopediaInfo } from '../blitz/tankopedia';
|
import { tankopediaInfo } from '../blitz/tankopedia';
|
||||||
import addPeriodSubCommands from './addPeriodSubCommands';
|
import addPeriodSubCommands from './addPeriodSubCommands';
|
||||||
import addTankChoices from './addTankChoices';
|
import addTankChoices from './addTankChoices';
|
||||||
|
import addTierChoices from './addTierChoices';
|
||||||
import addUsernameChoices from './addUsernameChoices';
|
import addUsernameChoices from './addUsernameChoices';
|
||||||
|
|
||||||
export default async function addStatTypeSubCommandGroups(
|
export default async function addStatTypeSubCommandGroups(
|
||||||
@@ -61,13 +62,8 @@ export default async function addStatTypeSubCommandGroups(
|
|||||||
)
|
)
|
||||||
.setRequired(false),
|
.setRequired(false),
|
||||||
)
|
)
|
||||||
.addIntegerOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
addTierChoices(option).setRequired(false),
|
||||||
.setName('tier')
|
|
||||||
.setDescription('Tier')
|
|
||||||
.setMinValue(1)
|
|
||||||
.setMaxValue(10)
|
|
||||||
.setRequired(false),
|
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { SlashCommandStringOption } from 'discord.js';
|
||||||
|
import { range } from 'lodash';
|
||||||
|
import numberToRomanNumeral from '../blitz/numberToRomanNumeral';
|
||||||
|
|
||||||
|
export default function addTierChoices(option: SlashCommandStringOption) {
|
||||||
|
return option
|
||||||
|
.setName('tier')
|
||||||
|
.setDescription('The tier you want to see')
|
||||||
|
.setChoices(
|
||||||
|
...range(10, 0).map((tier) => ({
|
||||||
|
name: `Tier ${tier} - ${numberToRomanNumeral(tier)}`,
|
||||||
|
value: `${tier}`,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.setRequired(true);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user