mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: used dahses for command readibility
This commit is contained in:
1 parent
23dd088466
commit
91f364b76a
13 files changed
+37
-49
No files matched your search
@@ -21,7 +21,7 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
||||
async (resolve) => {
|
||||
const command = await addStatTypeSubCommandGroups(
|
||||
new SlashCommandBuilder()
|
||||
.setName('fullstats')
|
||||
.setName('full-stats')
|
||||
.setDescription('Full in-game statistics'),
|
||||
);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('ownedtanks')
|
||||
.setName('owned-tanks')
|
||||
.setDescription("Shows a player's owned tanks")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
|
||||
@@ -20,7 +20,7 @@ export const playerAchievementsCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerachievements')
|
||||
.setName('player-achievements')
|
||||
.setDescription("All the player's achievements")
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addStringOption((option) =>
|
||||
|
||||
@@ -16,7 +16,7 @@ export const playerInfoCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('playerinfo')
|
||||
.setName('player-info')
|
||||
.setDescription('Basic information about a player')
|
||||
.addStringOption(addUsernameChoices),
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export const searchClansCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchclans')
|
||||
.setName('search-clans')
|
||||
.setDescription('Search clans')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) => addClanChoices(option).setAutocomplete(false))
|
||||
|
||||
@@ -16,7 +16,7 @@ export const searchPlayersCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchplayers')
|
||||
.setName('search-players')
|
||||
.setDescription('Search players in a Blitz server')
|
||||
.addStringOption(addRegionChoices)
|
||||
.addStringOption((option) =>
|
||||
|
||||
@@ -12,7 +12,7 @@ export const searchTanksCommand: CommandRegistry = {
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchtanks')
|
||||
.setName('search-tanks')
|
||||
.setDescription('Search tanks')
|
||||
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
|
||||
.addIntegerOption((option) =>
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodOption } from '../discord/addPeriodSubCommands';
|
||||
import getTimeDaysAgo from './getTimeDaysAgo';
|
||||
|
||||
export default function getPeriodStart(
|
||||
server: Region,
|
||||
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]!));
|
||||
}
|
||||
export default function getPeriodStart(region: Region, period: PeriodOption) {
|
||||
return period === 'career' ? 0 : getTimeDaysAgo(region, parseInt(period));
|
||||
}
|
||||
@@ -6,13 +6,13 @@ export const TIME_ZONE_MAPPINGS: Record<Region, number> = {
|
||||
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();
|
||||
if (daysAgo === 0) now.getTime() / 1000;
|
||||
|
||||
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);
|
||||
time.setUTCDate(time.getUTCDate() - daysAgo + 1);
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
} from 'discord.js';
|
||||
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(
|
||||
option: SlashCommandSubcommandGroupBuilder,
|
||||
@@ -16,18 +17,18 @@ export default function addPeriodSubCommands(
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('period' satisfies Period)
|
||||
.setName('period' satisfies PeriodSubcommand)
|
||||
.setDescription(PERIOD_NAMES.period)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('days')
|
||||
.setName('period')
|
||||
.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' },
|
||||
{ name: 'Today', value: '1' satisfies PeriodOption },
|
||||
{ name: '30 days', value: '30' satisfies PeriodOption },
|
||||
{ name: '60 days', value: '60' satisfies PeriodOption },
|
||||
{ name: '90 days', value: '90' satisfies PeriodOption },
|
||||
{ name: 'Career', value: 'career' satisfies PeriodOption },
|
||||
)
|
||||
.setRequired(true),
|
||||
),
|
||||
@@ -36,8 +37,8 @@ export default function addPeriodSubCommands(
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('customperiod' satisfies Period)
|
||||
.setDescription(PERIOD_NAMES.customperiod)
|
||||
.setName('custom' satisfies PeriodSubcommand)
|
||||
.setDescription(PERIOD_NAMES.custom)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('start')
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async function addStatTypeSubCommandGroups(
|
||||
})
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('tanktype')
|
||||
.setName('tank-type')
|
||||
.setDescription('Type')
|
||||
.addChoices(
|
||||
...Object.entries(awaitedTankopediaInfo.vehicle_types).map(
|
||||
@@ -65,7 +65,7 @@ export default async function addStatTypeSubCommandGroups(
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('treetype')
|
||||
.setName('tree-type')
|
||||
.setDescription('Tech tree type')
|
||||
.addChoices(
|
||||
{ name: 'Tech Tree', value: 'techtree' },
|
||||
@@ -75,7 +75,7 @@ export default async function addStatTypeSubCommandGroups(
|
||||
.setRequired(false),
|
||||
),
|
||||
)
|
||||
.setName('tanks')
|
||||
.setName('multi-tank')
|
||||
.setDescription('Multiple tanks'),
|
||||
);
|
||||
}
|
||||
@@ -3,20 +3,16 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
|
||||
|
||||
export const PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's statistics",
|
||||
period: "Set number of days' statistics",
|
||||
career: 'Career statistics',
|
||||
customperiod: 'Custom period',
|
||||
export const PERIOD_NAMES: Record<PeriodSubcommand, string> = {
|
||||
period: "Preset period's statistics",
|
||||
custom: "Custom period's statistics",
|
||||
};
|
||||
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's evolution",
|
||||
period: "Set number of days' evolution",
|
||||
career: 'Career evolution',
|
||||
customperiod: 'Custom period',
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<PeriodSubcommand, string> = {
|
||||
period: "Preset period's evolution",
|
||||
custom: "Custom period's evolution",
|
||||
};
|
||||
|
||||
export interface ResolvedPeriod {
|
||||
@@ -34,9 +30,9 @@ export default function resolvePeriodFromCommand(
|
||||
let evolutionName: string;
|
||||
let start: 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 endRaw = interaction.options.getInteger('end')!;
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
|
||||
import {
|
||||
EVOLUTION_PERIOD_NAMES,
|
||||
PERIOD_NAMES,
|
||||
@@ -19,7 +19,7 @@ export default function resolvePeriodFromURL(
|
||||
let end: number;
|
||||
const url = new URL(urlString);
|
||||
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') {
|
||||
const startRaw = parseInt(url!.searchParams.get('start')!);
|
||||
|
||||
Reference in new issue
Block a user