mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +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,15 +1,10 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
||||
import { TanksStats } from '../../types/tanksStats.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
||||
import errorWithCause from '../process/errorWithCause.js';
|
||||
import getWargamingResponse from './getWargamingResponse.js';
|
||||
|
||||
export default async function getTankStats(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
server: BlitzServer,
|
||||
id: number,
|
||||
) {
|
||||
export default async function getTankStats(server: BlitzServer, id: number) {
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
|
||||
@@ -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}/`,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { SlashCommandSubcommandBuilder } from 'discord.js';
|
||||
|
||||
export default function addCustomPeriodOption(
|
||||
option: SlashCommandSubcommandBuilder,
|
||||
) {
|
||||
return option
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('start')
|
||||
.setDescription('Start of period in days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('end')
|
||||
.setDescription('End of period in days ago from today')
|
||||
.setMinValue(0)
|
||||
.setRequired(true),
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export const statPeriodNames: Record<StatPeriod, string> = {
|
||||
90: '90-day statistics',
|
||||
career: 'Career statistics',
|
||||
};
|
||||
export default function addStatPeriodChoices(option: SlashCommandStringOption) {
|
||||
export default function addPeriodChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('period')
|
||||
.setDescription('The period to get stats for')
|
||||
@@ -3,6 +3,8 @@ import { SlashCommandStringOption } from 'discord.js';
|
||||
export default function addUsernameOption(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('username')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setDescription(
|
||||
'The username you use in Blitz (inferred from Discord nickname by default)',
|
||||
)
|
||||
.setAutocomplete(true);
|
||||
}
|
||||
Reference in new issue
Block a user