feat: used dahses for command readibility

This commit is contained in:
TresAbhi committed 2023-08-04 02:24:14 +00:00
1 parent 23dd088466
commit 91f364b76a
13 files changed
+37 -49

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
async (resolve) => { async (resolve) => {
const command = await addStatTypeSubCommandGroups( const command = await addStatTypeSubCommandGroups(
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('fullstats') .setName('full-stats')
.setDescription('Full in-game statistics'), .setDescription('Full in-game statistics'),
); );
+1 -1
View File
@@ -49,7 +49,7 @@ export const ownedTanksCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('ownedtanks') .setName('owned-tanks')
.setDescription("Shows a player's owned tanks") .setDescription("Shows a player's owned tanks")
.addStringOption((option) => .addStringOption((option) =>
option option
+1 -1
View File
@@ -20,7 +20,7 @@ export const playerAchievementsCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('playerachievements') .setName('player-achievements')
.setDescription("All the player's achievements") .setDescription("All the player's achievements")
.addStringOption(addUsernameChoices) .addStringOption(addUsernameChoices)
.addStringOption((option) => .addStringOption((option) =>
+1 -1
View File
@@ -16,7 +16,7 @@ export const playerInfoCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('playerinfo') .setName('player-info')
.setDescription('Basic information about a player') .setDescription('Basic information about a player')
.addStringOption(addUsernameChoices), .addStringOption(addUsernameChoices),
+1 -1
View File
@@ -15,7 +15,7 @@ export const searchClansCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('searchclans') .setName('search-clans')
.setDescription('Search clans') .setDescription('Search clans')
.addStringOption(addRegionChoices) .addStringOption(addRegionChoices)
.addStringOption((option) => addClanChoices(option).setAutocomplete(false)) .addStringOption((option) => addClanChoices(option).setAutocomplete(false))
+1 -1
View File
@@ -16,7 +16,7 @@ export const searchPlayersCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('searchplayers') .setName('search-players')
.setDescription('Search players in a Blitz server') .setDescription('Search players in a Blitz server')
.addStringOption(addRegionChoices) .addStringOption(addRegionChoices)
.addStringOption((option) => .addStringOption((option) =>
+1 -1
View File
@@ -12,7 +12,7 @@ export const searchTanksCommand: CommandRegistry = {
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('searchtanks') .setName('search-tanks')
.setDescription('Search tanks') .setDescription('Search tanks')
.addStringOption((option) => addTankChoices(option).setAutocomplete(false)) .addStringOption((option) => addTankChoices(option).setAutocomplete(false))
.addIntegerOption((option) => .addIntegerOption((option) =>
+3 -12
View File
@@ -1,16 +1,7 @@
import { Region } from '../../constants/regions'; import { Region } from '../../constants/regions';
import { Period } from '../discord/addPeriodSubCommands'; import { PeriodOption } from '../discord/addPeriodSubCommands';
import getTimeDaysAgo from './getTimeDaysAgo'; import getTimeDaysAgo from './getTimeDaysAgo';
export default function getPeriodStart( export default function getPeriodStart(region: Region, period: PeriodOption) {
server: Region, return period === 'career' ? 0 : getTimeDaysAgo(region, parseInt(period));
period: Exclude<Period, 'customperiod'>,
) {
if (period === 'career') {
return -Infinity;
} else if (period === 'today') {
return getTimeDaysAgo(server, 1);
} else {
return getTimeDaysAgo(server, parseInt(period.match(/\d+/)?.[0]!));
}
} }
+2 -2
View File
@@ -6,13 +6,13 @@ export const TIME_ZONE_MAPPINGS: Record<Region, number> = {
asia: +7, // Central Asia Standard Time asia: +7, // Central Asia Standard Time
}; };
export default function getTimeDaysAgo(server: Region, daysAgo: number) { export default function getTimeDaysAgo(region: Region, daysAgo: number) {
const now = new Date(); const now = new Date();
if (daysAgo === 0) now.getTime() / 1000; if (daysAgo === 0) now.getTime() / 1000;
const time = new Date(); const time = new Date();
time.setUTCHours(-TIME_ZONE_MAPPINGS[server], 0, 0, 0); time.setUTCHours(-TIME_ZONE_MAPPINGS[region], 0, 0, 0);
if (time > now) time.setUTCDate(time.getUTCDate() - 1); if (time > now) time.setUTCDate(time.getUTCDate() - 1);
time.setUTCDate(time.getUTCDate() - daysAgo + 1); time.setUTCDate(time.getUTCDate() - daysAgo + 1);
+11 -10
View File
@@ -4,7 +4,8 @@ import {
} from 'discord.js'; } from 'discord.js';
import { PERIOD_NAMES } from '../discord/resolvePeriodFromCommand'; import { PERIOD_NAMES } from '../discord/resolvePeriodFromCommand';
export type Period = 'period' | 'customperiod'; export type PeriodSubcommand = 'period' | 'custom';
export type PeriodOption = `${number}` | 'career';
export default function addPeriodSubCommands( export default function addPeriodSubCommands(
option: SlashCommandSubcommandGroupBuilder, option: SlashCommandSubcommandGroupBuilder,
@@ -16,18 +17,18 @@ export default function addPeriodSubCommands(
.addSubcommand((option) => .addSubcommand((option) =>
extra( extra(
option option
.setName('period' satisfies Period) .setName('period' satisfies PeriodSubcommand)
.setDescription(PERIOD_NAMES.period) .setDescription(PERIOD_NAMES.period)
.addStringOption((option) => .addStringOption((option) =>
option option
.setName('days') .setName('period')
.setDescription('A preset period') .setDescription('A preset period')
.setChoices( .setChoices(
{ name: 'Today', value: '1' }, { name: 'Today', value: '1' satisfies PeriodOption },
{ name: '30 days', value: '30' }, { name: '30 days', value: '30' satisfies PeriodOption },
{ name: '60 days', value: '60' }, { name: '60 days', value: '60' satisfies PeriodOption },
{ name: '90 days', value: '90' }, { name: '90 days', value: '90' satisfies PeriodOption },
{ name: 'Career', value: 'Infinity' }, { name: 'Career', value: 'career' satisfies PeriodOption },
) )
.setRequired(true), .setRequired(true),
), ),
@@ -36,8 +37,8 @@ export default function addPeriodSubCommands(
.addSubcommand((option) => .addSubcommand((option) =>
extra( extra(
option option
.setName('customperiod' satisfies Period) .setName('custom' satisfies PeriodSubcommand)
.setDescription(PERIOD_NAMES.customperiod) .setDescription(PERIOD_NAMES.custom)
.addIntegerOption((option) => .addIntegerOption((option) =>
option option
.setName('start') .setName('start')
@@ -43,7 +43,7 @@ export default async function addStatTypeSubCommandGroups(
}) })
.addStringOption((option) => .addStringOption((option) =>
option option
.setName('tanktype') .setName('tank-type')
.setDescription('Type') .setDescription('Type')
.addChoices( .addChoices(
...Object.entries(awaitedTankopediaInfo.vehicle_types).map( ...Object.entries(awaitedTankopediaInfo.vehicle_types).map(
@@ -65,7 +65,7 @@ export default async function addStatTypeSubCommandGroups(
) )
.addStringOption((option) => .addStringOption((option) =>
option option
.setName('treetype') .setName('tree-type')
.setDescription('Tech tree type') .setDescription('Tech tree type')
.addChoices( .addChoices(
{ name: 'Tech Tree', value: 'techtree' }, { name: 'Tech Tree', value: 'techtree' },
@@ -75,7 +75,7 @@ export default async function addStatTypeSubCommandGroups(
.setRequired(false), .setRequired(false),
), ),
) )
.setName('tanks') .setName('multi-tank')
.setDescription('Multiple tanks'), .setDescription('Multiple tanks'),
); );
} }
+9 -13
View File
@@ -3,20 +3,16 @@ import { Region } from '../../constants/regions';
import getPeriodNow from '../blitzstars/getPeriodNow'; import getPeriodNow from '../blitzstars/getPeriodNow';
import getPeriodStart from '../blitzstars/getPeriodStart'; import getPeriodStart from '../blitzstars/getPeriodStart';
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo'; import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
import { Period } from '../discord/addPeriodSubCommands'; import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
export const PERIOD_NAMES: Record<Period, string> = { export const PERIOD_NAMES: Record<PeriodSubcommand, string> = {
today: "Today's statistics", period: "Preset period's statistics",
period: "Set number of days' statistics", custom: "Custom period's statistics",
career: 'Career statistics',
customperiod: 'Custom period',
}; };
export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = { export const EVOLUTION_PERIOD_NAMES: Record<PeriodSubcommand, string> = {
today: "Today's evolution", period: "Preset period's evolution",
period: "Set number of days' evolution", custom: "Custom period's evolution",
career: 'Career evolution',
customperiod: 'Custom period',
}; };
export interface ResolvedPeriod { export interface ResolvedPeriod {
@@ -34,9 +30,9 @@ export default function resolvePeriodFromCommand(
let evolutionName: string; let evolutionName: string;
let start: number; let start: number;
let end: number; let end: number;
const period = interaction.options.getSubcommand() as Period; const period = interaction.options.getSubcommand() as PeriodSubcommand;
if (period === 'customperiod') { if (period === 'custom') {
const startRaw = interaction.options.getInteger('start')!; const startRaw = interaction.options.getInteger('start')!;
const endRaw = interaction.options.getInteger('end')!; const endRaw = interaction.options.getInteger('end')!;
const startMin = Math.min(startRaw, endRaw); const startMin = Math.min(startRaw, endRaw);
+2 -2
View File
@@ -2,7 +2,7 @@ import { Region } from '../../constants/regions';
import getPeriodNow from '../blitzstars/getPeriodNow'; import getPeriodNow from '../blitzstars/getPeriodNow';
import getPeriodStart from '../blitzstars/getPeriodStart'; import getPeriodStart from '../blitzstars/getPeriodStart';
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo'; import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
import { Period } from '../discord/addPeriodSubCommands'; import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
import { import {
EVOLUTION_PERIOD_NAMES, EVOLUTION_PERIOD_NAMES,
PERIOD_NAMES, PERIOD_NAMES,
@@ -19,7 +19,7 @@ export default function resolvePeriodFromURL(
let end: number; let end: number;
const url = new URL(urlString); const url = new URL(urlString);
const path = url.pathname.split('/').filter(Boolean); const path = url.pathname.split('/').filter(Boolean);
const period = path[path.length - 1] as Period; const period = path[path.length - 1] as PeriodSubcommand;
if (period === 'custom') { if (period === 'custom') {
const startRaw = parseInt(url!.searchParams.get('start')!); const startRaw = parseInt(url!.searchParams.get('start')!);