mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +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
@@ -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 addPeriodSubCommands from './addPeriodSubCommands';
|
||||
import addTankChoices from './addTankChoices';
|
||||
import addTierChoices from './addTierChoices';
|
||||
import addUsernameChoices from './addUsernameChoices';
|
||||
|
||||
export default async function addStatTypeSubCommandGroups(
|
||||
@@ -61,13 +62,8 @@ export default async function addStatTypeSubCommandGroups(
|
||||
)
|
||||
.setRequired(false),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('tier')
|
||||
.setDescription('Tier')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(10)
|
||||
.setRequired(false),
|
||||
.addStringOption((option) =>
|
||||
addTierChoices(option).setRequired(false),
|
||||
)
|
||||
.addStringOption((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