mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: updated /tankstats
This commit is contained in:
1 parent
50369e9225
commit
831300cf69
13 files changed
+300
-272
No files matched your search
@@ -18,7 +18,9 @@ export default async function tanksAutocomplete(
|
||||
? go(focusedOption.value, tanks, { keys: ['name'], limit: 10 }).map(
|
||||
(item) =>
|
||||
({
|
||||
name: item.obj.name ? item.obj.name : resolveTankName(item.obj),
|
||||
name: item.obj.name
|
||||
? item.obj.name
|
||||
: resolveTankName(item.obj.tank_id),
|
||||
value: `${item.obj.tank_id}`,
|
||||
} satisfies ApplicationCommandOptionChoiceData<string>),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { go } from 'fuzzysort';
|
||||
import { tankopedia, tanks } from '../blitzstars/tankopedia.js';
|
||||
import errorEmbed from '../interaction/errorEmbed.js';
|
||||
|
||||
export default async function resolveTankId(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
tank: string,
|
||||
) {
|
||||
const number = Number(tank);
|
||||
|
||||
if (Number.isNaN(number)) {
|
||||
const searchResult = go(tank, tanks, { keys: ['name'], limit: 1 });
|
||||
|
||||
if (searchResult.length === 0) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
errorEmbed(
|
||||
'Tank not found',
|
||||
`Could not find tank by the name "${tank}".`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
throw new Error(`Tank not found by name "${tank}"`);
|
||||
} else {
|
||||
return searchResult[0].obj.tank_id;
|
||||
}
|
||||
} else {
|
||||
if (tankopedia[number]) {
|
||||
return number;
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
errorEmbed(
|
||||
'Tank not found',
|
||||
`Could not find tank by the ID "${number}".`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
throw new Error(`Tank not found by ID "${number}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function getPeriodNow() {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { StatPeriod } from '../options/addStatPeriodChoices.js';
|
||||
|
||||
export default function getPeriodicStart(period: StatPeriod) {
|
||||
if (period === 'career') {
|
||||
return -Infinity;
|
||||
} else {
|
||||
const daysAgo = period === 'today' ? 0 : Number(period) - 1;
|
||||
const periodStart = new Date();
|
||||
|
||||
periodStart.setDate(periodStart.getDate() - daysAgo);
|
||||
periodStart.setHours(5, 0, 0, 0);
|
||||
|
||||
return periodStart.getTime() / 1000;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
export interface Period {
|
||||
statsId: number;
|
||||
account_id: number;
|
||||
tank_id: number;
|
||||
recordDate: string;
|
||||
last_battle_time: number;
|
||||
fromDate: string;
|
||||
prior_battle_time: number;
|
||||
battles: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
spotted: number;
|
||||
shots: number;
|
||||
hits: number;
|
||||
xp: number;
|
||||
battle_life_time: number;
|
||||
frags: number;
|
||||
max_frags: number;
|
||||
damage_dealt: number;
|
||||
damage_received: number;
|
||||
survived_battles: number;
|
||||
win_and_survived: number;
|
||||
capture_points: number;
|
||||
dropped_capture_points: number;
|
||||
killStealerValue: number;
|
||||
isRating: boolean;
|
||||
wn8: number;
|
||||
region: string;
|
||||
}
|
||||
|
||||
export default async function getPeriodicStats(id: number, period: number) {
|
||||
const response = await fetch(
|
||||
`https://blitztankstats.com/api/Stats/period/${id}/${period}`,
|
||||
);
|
||||
return (await response.json()) as Period[];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
|
||||
export type StatPeriod = 'today' | '30' | '60' | '90' | 'career';
|
||||
export const statPeriodNames: Record<StatPeriod, string> = {
|
||||
today: "Today's statistics",
|
||||
30: '30-day statistics',
|
||||
60: '60-day statistics',
|
||||
90: '90-day statistics',
|
||||
career: 'Career statistics',
|
||||
};
|
||||
export default function addStatPeriodChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('period')
|
||||
.setDescription('The period to get stats for')
|
||||
.setChoices(
|
||||
{ name: 'Today', value: 'today' satisfies StatPeriod },
|
||||
{ name: '30 Days', value: '30' satisfies StatPeriod },
|
||||
{ name: '60 Days', value: '60' satisfies StatPeriod },
|
||||
{ name: '90 Days', value: '90' satisfies StatPeriod },
|
||||
{ name: 'Career', value: 'career' satisfies StatPeriod },
|
||||
)
|
||||
.setRequired(true);
|
||||
}
|
||||
Reference in new issue
Block a user