mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
feat: extracted renderer from /stats
This commit is contained in:
1 parent
bcbc1e259f
commit
752f9b339b
21 files changed
+329
-273
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { serverAndIdPattern } from '../options/resolvePlayer.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import { serverAndIdPattern } from './getBlitzAccount.js';
|
||||
import listClansPanServer from './listClansPanServer.js';
|
||||
|
||||
export default async function getBlitzClan(
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default function getPeriodNow() {
|
||||
return new Date().getTime() / 1000;
|
||||
return Date.now() / 1000;
|
||||
}
|
||||
@@ -7,6 +7,6 @@ export default function getPeriodStart(period: Exclude<Period, 'custom'>) {
|
||||
} else if (period === 'today') {
|
||||
return getTimeDaysAgo(0);
|
||||
} else {
|
||||
return getTimeDaysAgo(Number(period));
|
||||
return getTimeDaysAgo(parseInt(period));
|
||||
}
|
||||
}
|
||||
@@ -88,5 +88,5 @@ export default async function getPlayerHistories(
|
||||
}
|
||||
}
|
||||
|
||||
return [...latestNodes, ...filtered, ...previousNodes] satisfies Histories;
|
||||
return [...previousNodes, ...filtered, ...latestNodes] satisfies Histories;
|
||||
}
|
||||
@@ -109,5 +109,5 @@ export default async function getTankHistories(
|
||||
});
|
||||
}
|
||||
|
||||
return [...latestNodes, ...filtered, ...previousNodes] satisfies Histories;
|
||||
return [...previousNodes, ...filtered, ...latestNodes] satisfies Histories;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { AllStats } from '../../types/accountInfo.js';
|
||||
import getTankHistories, {
|
||||
TankHistoriesRaw,
|
||||
TankHistories,
|
||||
TankHistoryRaw,
|
||||
} from './getTankHistories.js';
|
||||
|
||||
@@ -45,7 +45,7 @@ export default async function getTankStatsOverTime(
|
||||
});
|
||||
|
||||
// sort them even though most won't be used
|
||||
const tankSortedHistory: Record<number, TankHistoriesRaw> = {};
|
||||
const tankSortedHistory: Record<number, TankHistories> = {};
|
||||
const tankIds: number[] = [];
|
||||
history.forEach((node) => {
|
||||
if (!tankSortedHistory[node.tank_id]) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
|
||||
export default function generateCustomId(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
return `${interaction.commandName}/${
|
||||
interaction.options.getSubcommandGroup() ?? ''
|
||||
}/${interaction.options.getSubcommand() ?? ''}`;
|
||||
}
|
||||
@@ -2,15 +2,15 @@ import {
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { PERIOD_NAMES } from './getPeriodDataFromSubcommand.js';
|
||||
import { PERIOD_NAMES } from './resolvePeriod.js';
|
||||
|
||||
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',
|
||||
30: '30 days ago',
|
||||
60: '60 days ago',
|
||||
90: '90 days ago',
|
||||
career: 'Extent of data',
|
||||
custom: 'Custom period',
|
||||
};
|
||||
@@ -26,13 +26,13 @@ export default function addPeriodSubCommands(
|
||||
extra(option.setName('today').setDescription(PERIOD_NAMES.today)),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('30').setDescription(PERIOD_NAMES['30'])),
|
||||
extra(option.setName('30').setDescription(PERIOD_NAMES[30])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('60').setDescription(PERIOD_NAMES['60'])),
|
||||
extra(option.setName('60').setDescription(PERIOD_NAMES[60])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('90').setDescription(PERIOD_NAMES['90'])),
|
||||
extra(option.setName('90').setDescription(PERIOD_NAMES[90])),
|
||||
)
|
||||
.addSubcommand((option) =>
|
||||
extra(option.setName('career').setDescription(PERIOD_NAMES.career)),
|
||||
|
||||
+15
-8
@@ -6,23 +6,30 @@ import { Period } from './addPeriodSubCommands.js';
|
||||
|
||||
export const PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's statistics",
|
||||
'30': "30 days' statistics",
|
||||
'60': "60 days' statistics",
|
||||
'90': "90 days' statistics",
|
||||
30: "30 days' statistics",
|
||||
60: "60 days' statistics",
|
||||
90: "90 days' statistics",
|
||||
career: 'Career statistics',
|
||||
custom: 'Custom period',
|
||||
};
|
||||
|
||||
export const EVOLUTION_PERIOD_NAMES: Record<Period, string> = {
|
||||
today: "Today's evolution",
|
||||
'30': "30 days' evolution",
|
||||
'60': "60 days' evolution",
|
||||
'90': "90 days' evolution",
|
||||
30: "30 days' evolution",
|
||||
60: "60 days' evolution",
|
||||
90: "90 days' evolution",
|
||||
career: 'Career evolution',
|
||||
custom: 'Custom period',
|
||||
};
|
||||
|
||||
export default function getPeriodDataFromSubcommand(
|
||||
export interface ResolvedPeriod {
|
||||
statsName: string;
|
||||
evolutionName: string;
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
export default function resolvePeriod(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
const period = interaction.options.getSubcommand(true) as Period;
|
||||
@@ -48,5 +55,5 @@ export default function getPeriodDataFromSubcommand(
|
||||
end = getPeriodNow();
|
||||
}
|
||||
|
||||
return { statsName, evolutionName, start, end };
|
||||
return { statsName, evolutionName, start, end } satisfies ResolvedPeriod;
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import listAccountsPanServer, {
|
||||
usernamePatternWithoutPosition,
|
||||
} from './listAccountsPanServer.js';
|
||||
} from '../blitz/listAccountsPanServer.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
|
||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
|
||||
export default async function getBlitzAccount(
|
||||
export interface ResolvedPlayer {
|
||||
server: BlitzServer;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export default async function resolvePlayer(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
const commandUsername = interaction.options.getString('username');
|
||||
@@ -25,12 +30,18 @@ export default async function getBlitzAccount(
|
||||
|
||||
if (serverAndIdPattern.test(username)) {
|
||||
const [server, accountId] = username.split('/');
|
||||
return { server: server as BlitzServer, id: Number(accountId) };
|
||||
return {
|
||||
server: server as BlitzServer,
|
||||
id: Number(accountId),
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
const accounts = await listAccountsPanServer(username);
|
||||
|
||||
if (accounts[0]) {
|
||||
return { server: accounts[0].server, id: accounts[0].account_id };
|
||||
return {
|
||||
server: accounts[0].server,
|
||||
id: accounts[0].account_id,
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
throw errorWithCause(
|
||||
'Could not find user',
|
||||
Reference in new issue
Block a user