mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: custom periods for /stats and /tankstats
This commit is contained in:
1 parent
78424c1535
commit
e0c1db2a0b
14 files changed
+125
-49
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { StatPeriod } from '../options/addStatPeriodChoices.js';
|
||||
import { StatPeriod } from '../options/addPeriodChoices.js';
|
||||
import getPeriodStartFromDaysAgo from './getPeriodStartFromDaysAgo.js';
|
||||
|
||||
export default function getPeriodicStart(period: StatPeriod) {
|
||||
if (period === 'career') {
|
||||
@@ -12,12 +13,6 @@ export default function getPeriodicStart(period: StatPeriod) {
|
||||
|
||||
return now.getTime() / 1000;
|
||||
} else {
|
||||
const daysAgo = Number(period) - 1;
|
||||
const periodStart = new Date();
|
||||
|
||||
periodStart.setDate(periodStart.getDate() - daysAgo);
|
||||
periodStart.setHours(5, 0, 0, 0);
|
||||
|
||||
return periodStart.getTime() / 1000;
|
||||
return getPeriodStartFromDaysAgo(Number(period));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export default function getPeriodStartFromDaysAgo(period: number) {
|
||||
const daysAgo = Number(period) - 1;
|
||||
const periodStart = new Date();
|
||||
|
||||
periodStart.setDate(periodStart.getDate() - daysAgo);
|
||||
periodStart.setHours(5, 0, 0, 0);
|
||||
|
||||
return periodStart.getTime() / 1000;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { AllStats } from '../../types/accountInfo.js';
|
||||
import getTankStats from '../blitz/getTankStats.js';
|
||||
@@ -44,13 +43,12 @@ export const emptyTankHistoryNode: TankHistoryNode = {
|
||||
export type TankHistory = TankHistoryNode[];
|
||||
|
||||
export default async function getTankStatsOverTime(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
server: BlitzServer,
|
||||
id: number,
|
||||
start: number,
|
||||
end: number,
|
||||
) {
|
||||
const latestTankStatsRaw = await getTankStats(interaction, server, id);
|
||||
const latestTankStatsRaw = await getTankStats(server, id);
|
||||
const tankHistoriesResponse = await fetch(
|
||||
`https://www.blitzstars.com/api/tankhistories/for/${id}/`,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user