mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: added more mature periods
This commit is contained in:
1 parent
91f364b76a
commit
91dc45c880
27 files changed
+68
-67
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { PeriodOption } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize } from '../discord/addPeriodSubCommands';
|
||||
import getTimeDaysAgo from './getTimeDaysAgo';
|
||||
|
||||
export default function getPeriodStart(region: Region, period: PeriodOption) {
|
||||
export default function getPeriodStart(region: Region, period: PeriodSize) {
|
||||
return period === 'career' ? 0 : getTimeDaysAgo(region, parseInt(period));
|
||||
}
|
||||
@@ -2,10 +2,9 @@ import {
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { PERIOD_NAMES } from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export type PeriodSubcommand = 'period' | 'custom';
|
||||
export type PeriodOption = `${number}` | 'career';
|
||||
export type PeriodType = 'period' | 'custom';
|
||||
export type PeriodSize = `${number}` | 'career';
|
||||
|
||||
export default function addPeriodSubCommands(
|
||||
option: SlashCommandSubcommandGroupBuilder,
|
||||
@@ -17,18 +16,18 @@ export default function addPeriodSubCommands(
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('period' satisfies PeriodSubcommand)
|
||||
.setDescription(PERIOD_NAMES.period)
|
||||
.setName('period' satisfies PeriodType)
|
||||
.setDescription("Preset period's statistics")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('period')
|
||||
.setDescription('A preset period')
|
||||
.setChoices(
|
||||
{ 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 },
|
||||
{ name: 'Today', value: '1' satisfies PeriodSize },
|
||||
{ name: '30 days', value: '30' satisfies PeriodSize },
|
||||
{ name: '60 days', value: '60' satisfies PeriodSize },
|
||||
{ name: '90 days', value: '90' satisfies PeriodSize },
|
||||
{ name: 'Career', value: 'career' satisfies PeriodSize },
|
||||
)
|
||||
.setRequired(true),
|
||||
),
|
||||
@@ -37,19 +36,19 @@ export default function addPeriodSubCommands(
|
||||
.addSubcommand((option) =>
|
||||
extra(
|
||||
option
|
||||
.setName('custom' satisfies PeriodSubcommand)
|
||||
.setDescription(PERIOD_NAMES.custom)
|
||||
.setName('custom' satisfies PeriodType)
|
||||
.setDescription("Custom period's statistics")
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('start')
|
||||
.setDescription('Start of period in days ago from today')
|
||||
.setDescription('Days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('end')
|
||||
.setDescription('End of period in days ago from today')
|
||||
.setDescription('Days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
@@ -29,6 +29,7 @@ export default async function addStatTypeSubCommandGroups(
|
||||
.addSubcommandGroup((option) =>
|
||||
addPeriodSubCommands(option, (option) =>
|
||||
option
|
||||
.addStringOption(addUsernameChoices)
|
||||
.addStringOption((option) => {
|
||||
option
|
||||
.setName('nation')
|
||||
|
||||
@@ -3,17 +3,11 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize, PeriodType } from '../discord/addPeriodSubCommands';
|
||||
|
||||
export const PERIOD_NAMES: Record<PeriodSubcommand, string> = {
|
||||
period: "Preset period's statistics",
|
||||
custom: "Custom period's statistics",
|
||||
};
|
||||
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<PeriodSubcommand, string> = {
|
||||
period: "Preset period's evolution",
|
||||
custom: "Custom period's evolution",
|
||||
};
|
||||
export function getPeriodOptionName(period: PeriodSize) {
|
||||
return period === 'career' ? 'Career' : `${period}-day`;
|
||||
}
|
||||
|
||||
export interface ResolvedPeriod {
|
||||
statsName: string;
|
||||
@@ -30,9 +24,10 @@ export default function resolvePeriodFromCommand(
|
||||
let evolutionName: string;
|
||||
let start: number;
|
||||
let end: number;
|
||||
const period = interaction.options.getSubcommand() as PeriodSubcommand;
|
||||
const periodSubcommand = interaction.options.getSubcommand() as PeriodType;
|
||||
const periodOption = interaction.options.getString('period') as PeriodSize;
|
||||
|
||||
if (period === 'custom') {
|
||||
if (periodSubcommand === 'custom') {
|
||||
const startRaw = interaction.options.getInteger('start')!;
|
||||
const endRaw = interaction.options.getInteger('end')!;
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
@@ -43,9 +38,9 @@ export default function resolvePeriodFromCommand(
|
||||
start = getTimeDaysAgo(server, startMin);
|
||||
end = getTimeDaysAgo(server, endMax);
|
||||
} else {
|
||||
statsName = PERIOD_NAMES[period];
|
||||
evolutionName = EVOLUTION_PERIOD_NAMES[period];
|
||||
start = getPeriodStart(server, period);
|
||||
statsName = `${getPeriodOptionName(periodOption)} Statistics`;
|
||||
evolutionName = `${getPeriodOptionName(periodOption)} Evolution`;
|
||||
start = getPeriodStart(server, periodOption);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { PeriodSubcommand } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize, PeriodType } from '../discord/addPeriodSubCommands';
|
||||
import {
|
||||
EVOLUTION_PERIOD_NAMES,
|
||||
PERIOD_NAMES,
|
||||
ResolvedPeriod,
|
||||
getPeriodOptionName,
|
||||
} from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromURL(
|
||||
@@ -19,9 +18,10 @@ 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 PeriodSubcommand;
|
||||
const periodSubcommand = path[path.length - 1] as PeriodType;
|
||||
const periodOption = url.searchParams.get('period') as PeriodSize;
|
||||
|
||||
if (period === 'custom') {
|
||||
if (periodSubcommand === 'custom') {
|
||||
const startRaw = parseInt(url!.searchParams.get('start')!);
|
||||
const endRaw = parseInt(url!.searchParams.get('end')!);
|
||||
const startMin = Math.min(startRaw, endRaw);
|
||||
@@ -32,9 +32,9 @@ export default function resolvePeriodFromURL(
|
||||
start = getTimeDaysAgo(server, startMin);
|
||||
end = getTimeDaysAgo(server, endMax);
|
||||
} else {
|
||||
statsName = PERIOD_NAMES[period];
|
||||
evolutionName = EVOLUTION_PERIOD_NAMES[period];
|
||||
start = getPeriodStart(server, period);
|
||||
statsName = `${getPeriodOptionName(periodOption)} Statistics`;
|
||||
evolutionName = `${getPeriodOptionName(periodOption)} Evolution`;
|
||||
start = getPeriodStart(server, periodOption);
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user