mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
Merge pull request #12 from tresabhi/main
This commit is contained in:
4 files changed
+6
-31
No files matched your search
@@ -11,7 +11,7 @@ import { StatType } from '../renderers/stats.js';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
inPublic: true,
|
inPublic: true,
|
||||||
|
|
||||||
command: addStatsSubCommandGroups(
|
command: addStatsSubCommandGroups(
|
||||||
|
|||||||
@@ -6,15 +6,6 @@ import { PERIOD_NAMES } from './resolvePeriod.js';
|
|||||||
|
|
||||||
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
||||||
|
|
||||||
export const RELATIVE_PERIOD_NAMES: Record<Period, string> = {
|
|
||||||
today: 'A day ago',
|
|
||||||
30: '30 days ago',
|
|
||||||
60: '60 days ago',
|
|
||||||
90: '90 days ago',
|
|
||||||
career: 'Extent of data',
|
|
||||||
custom: 'Custom period',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function addPeriodSubCommands(
|
export default function addPeriodSubCommands(
|
||||||
option: SlashCommandSubcommandGroupBuilder,
|
option: SlashCommandSubcommandGroupBuilder,
|
||||||
extra: (
|
extra: (
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { CYCLIC_API } from '../../constants/cyclic.js';
|
|||||||
import getPeriodNow from '../blitzstars/getPeriodNow.js';
|
import getPeriodNow from '../blitzstars/getPeriodNow.js';
|
||||||
import getPeriodStart from '../blitzstars/getPeriodStart.js';
|
import getPeriodStart from '../blitzstars/getPeriodStart.js';
|
||||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
|
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
|
||||||
import { Period, RELATIVE_PERIOD_NAMES } from './addPeriodSubCommands.js';
|
import { Period } from './addPeriodSubCommands.js';
|
||||||
|
|
||||||
export const PERIOD_NAMES: Record<Period, string> = {
|
export const PERIOD_NAMES: Record<Period, string> = {
|
||||||
today: "Today's statistics",
|
today: "Today's statistics",
|
||||||
@@ -28,7 +28,6 @@ export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface ResolvedPeriod {
|
export interface ResolvedPeriod {
|
||||||
relativePeriodName: string;
|
|
||||||
statsName: string;
|
statsName: string;
|
||||||
evolutionName: string;
|
evolutionName: string;
|
||||||
start: number;
|
start: number;
|
||||||
@@ -44,21 +43,6 @@ export default function resolvePeriod(
|
|||||||
let evolutionName: string;
|
let evolutionName: string;
|
||||||
let start: number;
|
let start: number;
|
||||||
let end: number;
|
let end: number;
|
||||||
let subcommand: Period;
|
|
||||||
let url: typeof interaction extends ChatInputCommandInteraction
|
|
||||||
? undefined
|
|
||||||
: URL;
|
|
||||||
|
|
||||||
if (interaction instanceof ChatInputCommandInteraction) {
|
|
||||||
subcommand = interaction.options.getSubcommand() as Period;
|
|
||||||
} else {
|
|
||||||
url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
|
||||||
subcommand = path[path.length - 1] as Period;
|
|
||||||
}
|
|
||||||
|
|
||||||
const period = subcommand;
|
|
||||||
const relativePeriodName = RELATIVE_PERIOD_NAMES[subcommand];
|
|
||||||
|
|
||||||
if (period === 'custom') {
|
if (period === 'custom') {
|
||||||
const startRaw =
|
const startRaw =
|
||||||
@@ -88,6 +72,5 @@ export default function resolvePeriod(
|
|||||||
evolutionName,
|
evolutionName,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
relativePeriodName,
|
|
||||||
} satisfies ResolvedPeriod;
|
} satisfies ResolvedPeriod;
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ import { StatType } from './stats.js';
|
|||||||
|
|
||||||
export default async function evolution<Type extends StatType>(
|
export default async function evolution<Type extends StatType>(
|
||||||
type: Type,
|
type: Type,
|
||||||
{ start, end, evolutionName, relativePeriodName }: ResolvedPeriod,
|
{ start, end, evolutionName }: ResolvedPeriod,
|
||||||
{ server, id }: ResolvedPlayer,
|
{ server, id }: ResolvedPlayer,
|
||||||
tankId: Type extends 'tank' ? number : never,
|
tankId: Type extends 'tank' ? number : never,
|
||||||
) {
|
) {
|
||||||
@@ -78,6 +78,7 @@ export default async function evolution<Type extends StatType>(
|
|||||||
const battleYs = careerBattles.map(([, y]) => y);
|
const battleYs = careerBattles.map(([, y]) => y);
|
||||||
const maxBattle = Math.max(...battleYs);
|
const maxBattle = Math.max(...battleYs);
|
||||||
const minBattle = Math.min(...battleYs);
|
const minBattle = Math.min(...battleYs);
|
||||||
|
const minTime = Math.min(...careerBattles.map(([x]) => x));
|
||||||
|
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
@@ -97,8 +98,8 @@ export default async function evolution<Type extends StatType>(
|
|||||||
{/* goofy ahh bug forces me to call them as functions */}
|
{/* goofy ahh bug forces me to call them as functions */}
|
||||||
{careerWinrate.length > 0 && (
|
{careerWinrate.length > 0 && (
|
||||||
<Graph.Root
|
<Graph.Root
|
||||||
xMinLabel={relativePeriodName}
|
xMinLabel={new Date(minTime * 1000).toDateString()}
|
||||||
xMaxLabel="Latest recorded battle" // TODO: this is not true in custom periods
|
xMaxLabel={new Date(end * 1000).toDateString()}
|
||||||
leftVerticalMargin={{
|
leftVerticalMargin={{
|
||||||
min: minWinrate,
|
min: minWinrate,
|
||||||
max: maxWinrate,
|
max: maxWinrate,
|
||||||
|
|||||||
Reference in new issue
Block a user