mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: made WARGAMING_APPLICATION_ID public
This commit is contained in:
1 parent
018783bb47
commit
e37e0ccf9f
31 files changed
+196
-80
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
IndividualTankStats,
|
||||
NormalizedTankStats,
|
||||
emptyIndividualTankStats,
|
||||
} from '../../types/tanksStats';
|
||||
|
||||
export function diffNormalizedTankStats(
|
||||
a: NormalizedTankStats,
|
||||
b: NormalizedTankStats,
|
||||
) {
|
||||
const bTanks = Object.keys(b);
|
||||
const changedTanks = bTanks.filter((id) => {
|
||||
return (
|
||||
a[id as unknown as number]?.all.battles !==
|
||||
b[id as unknown as number].all.battles
|
||||
);
|
||||
});
|
||||
const diff = changedTanks.map((id) => {
|
||||
const aTank = a[id as unknown as number] ?? emptyIndividualTankStats;
|
||||
const bTank = b[id as unknown as number];
|
||||
|
||||
const tankDiff = {
|
||||
account_id: bTank.account_id,
|
||||
battle_life_time: bTank.battle_life_time,
|
||||
frags: (bTank.frags ?? aTank.frags ?? 0) - (aTank.frags ?? 0),
|
||||
max_frags: Math.max(aTank.max_frags, bTank.max_frags),
|
||||
in_garage: bTank.in_garage,
|
||||
max_xp: Math.max(aTank.max_xp, bTank.max_xp),
|
||||
in_garage_updated: bTank.in_garage_updated,
|
||||
last_battle_time: bTank.last_battle_time - aTank.last_battle_time,
|
||||
mark_of_mastery: bTank.mark_of_mastery,
|
||||
tank_id: bTank.tank_id,
|
||||
|
||||
all: {
|
||||
battles: bTank.all.battles - aTank.all.battles,
|
||||
wins: bTank.all.wins - aTank.all.wins,
|
||||
capture_points: bTank.all.capture_points - aTank.all.capture_points,
|
||||
damage_dealt: bTank.all.damage_dealt - aTank.all.damage_dealt,
|
||||
damage_received: bTank.all.damage_received - aTank.all.damage_received,
|
||||
dropped_capture_points:
|
||||
bTank.all.dropped_capture_points - aTank.all.dropped_capture_points,
|
||||
frags: bTank.all.frags - aTank.all.frags,
|
||||
frags8p: bTank.all.frags8p - aTank.all.frags8p,
|
||||
hits: bTank.all.hits - aTank.all.hits,
|
||||
losses: bTank.all.losses - aTank.all.losses,
|
||||
max_frags: Math.max(aTank.max_frags, bTank.max_frags),
|
||||
max_xp: Math.max(aTank.max_xp, bTank.max_xp),
|
||||
shots: bTank.all.shots - aTank.all.shots,
|
||||
spotted: bTank.all.spotted - aTank.all.spotted,
|
||||
survived_battles:
|
||||
bTank.all.survived_battles - aTank.all.survived_battles,
|
||||
win_and_survived:
|
||||
bTank.all.win_and_survived - aTank.all.win_and_survived,
|
||||
xp: bTank.all.xp - aTank.all.xp,
|
||||
},
|
||||
} satisfies IndividualTankStats;
|
||||
|
||||
return tankDiff;
|
||||
});
|
||||
const normalized = diff.reduce<NormalizedTankStats>(
|
||||
(accumulator, diff) => ({ ...accumulator, [diff.tank_id]: diff }),
|
||||
{},
|
||||
);
|
||||
|
||||
return normalized;
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { REGION_NAMES, Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { TankStats } from '../../types/tanksStats';
|
||||
import { secrets } from '../node/secrets';
|
||||
import throwError from '../node/throwError';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export default async function getTankStats(region: Region, id: number) {
|
||||
const tankStats = await getWargamingResponse<TankStats>(
|
||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
|
||||
if (tankStats[id] === null) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { Clan, ClanList } from '../../types/clanList';
|
||||
import { secrets } from '../node/secrets';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export type ClanListWithRegion = (Clan & {
|
||||
@@ -15,7 +15,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
return (
|
||||
await Promise.all([
|
||||
getWargamingResponse<ClanList>(
|
||||
`https://api.wotblitz.com/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
@@ -25,7 +25,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<ClanList>(
|
||||
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
@@ -35,7 +35,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<ClanList>(
|
||||
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { secrets } from '../node/secrets';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
interface Account {
|
||||
@@ -23,7 +23,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
return (
|
||||
await Promise.all([
|
||||
getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.com/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
@@ -33,7 +33,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.eu/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
@@ -43,7 +43,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.asia/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
`https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`,
|
||||
).then(
|
||||
(value) =>
|
||||
value &&
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { deburr } from 'lodash';
|
||||
import { secrets } from '../node/secrets';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank';
|
||||
@@ -66,7 +66,7 @@ export interface TankopediaInfo {
|
||||
// this is blocking because info is needed for command creation
|
||||
console.log('Caching tankopedia info...');
|
||||
export const tankopediaInfo = getWargamingResponse<TankopediaInfo>(
|
||||
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}`,
|
||||
`https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${WARGAMING_APPLICATION_ID}`,
|
||||
);
|
||||
console.log('Cached tankopedia info');
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ export const emptyTankHistoryNode: TankHistoryRaw = {
|
||||
all: emptyAllStats,
|
||||
};
|
||||
|
||||
// BIG TODO: merge this neatly with diffNormalizedTankStats
|
||||
export default async function getDiffedTankStats(
|
||||
server: Region,
|
||||
id: number,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { AccountInfo, AllStats } from '../../types/accountInfo';
|
||||
import {
|
||||
GetHistoriesOptions,
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
getHistoriesDefaultOptions,
|
||||
} from '../../types/histories';
|
||||
import getWargamingResponse from '../blitz/getWargamingResponse';
|
||||
import { secrets } from '../node/secrets';
|
||||
import { emptyAllStats } from './getDiffedTankStats';
|
||||
|
||||
export interface PlayerHistoryRaw {
|
||||
@@ -67,7 +67,7 @@ export default async function getPlayerHistories(
|
||||
statistics: { all },
|
||||
} = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
)[id];
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@ import { config } from 'dotenv';
|
||||
|
||||
config();
|
||||
|
||||
export const SECRET_KEYS = [
|
||||
'DISCORD_TOKEN',
|
||||
'WARGAMING_APPLICATION_ID',
|
||||
'GH_TOKEN',
|
||||
] as const;
|
||||
export const SECRET_KEYS = ['DISCORD_TOKEN', 'GH_TOKEN'] as const;
|
||||
|
||||
export type SECRET = typeof SECRET_KEYS extends readonly (infer T)[]
|
||||
? T
|
||||
|
||||
Reference in new issue
Block a user