mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
fix: tank stats being null for players without battles
This commit is contained in:
1 parent
99135f25c7
commit
96ae6b715f
6 files changed
+48
-22
No files matched your search
@@ -2,6 +2,7 @@ import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
||||
import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitz/tankopedia.js';
|
||||
@@ -11,7 +12,6 @@ import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { TanksStats } from '../types/tanksStats.js';
|
||||
|
||||
const COMP_TANKS = [
|
||||
// light tanks
|
||||
@@ -60,10 +60,8 @@ export default {
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tanks = tankStats[id]
|
||||
const tankStats = await getTankStats(interaction, server, id);
|
||||
const tanks = tankStats
|
||||
.map((tankData) => tankopedia[tankData.tank_id])
|
||||
.filter((tank) => tank?.tier === tier);
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ export default {
|
||||
stats = accountInfo[id].statistics.all;
|
||||
} else {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
getPeriodicStart(period),
|
||||
|
||||
@@ -12,6 +12,7 @@ import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import tanksAutocomplete from '../core/autocomplete/tanks.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankId from '../core/blitz/resolveTankId.js';
|
||||
@@ -36,7 +37,6 @@ import { args } from '../core/process/args.js';
|
||||
import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
import { TanksStats } from '../types/tanksStats.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
@@ -62,18 +62,17 @@ export default {
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const tankStats = await getTankStats(interaction, server, id);
|
||||
let stats: AllStats;
|
||||
const tankId = Number(tank);
|
||||
|
||||
if (period === 'career') {
|
||||
stats =
|
||||
tankStats[id].find((stats) => stats.tank_id === tankId)?.all ??
|
||||
tankStats.find((stats) => stats.tank_id === tankId)?.all ??
|
||||
emptyAllStats;
|
||||
} else {
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
getPeriodicStart(period),
|
||||
|
||||
@@ -11,6 +11,7 @@ import Wrapper, { WrapperSize } from '../components/Wrapper.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getTankStats from '../core/blitz/getTankStats.js';
|
||||
import getWN8 from '../core/blitz/getWN8.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import resolveTankName from '../core/blitz/resolveTankName.js';
|
||||
@@ -28,7 +29,6 @@ import render from '../core/ui/render.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
import { PlayerClanData } from '../types/playerClanData.js';
|
||||
import { TanksStats } from '../types/tanksStats.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
@@ -45,6 +45,7 @@ export default {
|
||||
const blitzAccount = await getBlitzAccount(interaction, username);
|
||||
const { id, server } = blitzAccount;
|
||||
const tankStatsOverTime = await getTankStatsOverTime(
|
||||
interaction,
|
||||
server,
|
||||
id,
|
||||
last5AM().getTime() / 1000,
|
||||
@@ -56,9 +57,7 @@ export default {
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const careerTankStatsRaw = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
const careerTankStatsRaw = await getTankStats(interaction, server, id);
|
||||
const careerStats: Record<number, AllStats> = {
|
||||
0: accountInfo[id].statistics.all,
|
||||
};
|
||||
@@ -67,7 +66,7 @@ export default {
|
||||
Object.entries(tankStatsOverTime).forEach(([, tankStats]) => {
|
||||
allStatsToAccumulate.push(tankStats);
|
||||
});
|
||||
Object.entries(careerTankStatsRaw[id]).forEach(([, tankStats]) => {
|
||||
Object.entries(careerTankStatsRaw).forEach(([, tankStats]) => {
|
||||
careerStats[tankStats.tank_id] = tankStats.all;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user