2024-03-09 11:48:35 -06:00
|
|
|
import { Locale } from 'discord.js';
|
2023-10-14 10:58:48 -05:00
|
|
|
import { Region } from '../../constants/regions';
|
2023-09-23 21:51:00 +00:00
|
|
|
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
2024-02-17 10:20:43 -06:00
|
|
|
import { UserError } from '../../hooks/userError';
|
2023-09-23 19:20:29 -05:00
|
|
|
import { TanksStats } from '../../types/tanksStats';
|
2024-03-09 11:48:35 -06:00
|
|
|
import { translator } from '../localization/translator';
|
2023-10-20 10:50:54 -05:00
|
|
|
import fetchBlitz from './fetchBlitz';
|
2023-06-03 01:19:52 +00:00
|
|
|
|
2024-03-09 11:48:35 -06:00
|
|
|
export default async function getTankStats(
|
|
|
|
|
region: Region,
|
|
|
|
|
id: number,
|
|
|
|
|
locale: Locale,
|
|
|
|
|
) {
|
|
|
|
|
const { t } = translator(locale);
|
2023-10-14 10:58:48 -05:00
|
|
|
const tankStats = await fetchBlitz<TanksStats>(
|
2023-09-23 21:51:00 +00:00
|
|
|
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
2023-06-03 01:19:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (tankStats[id] === null) {
|
2024-03-09 11:48:35 -06:00
|
|
|
throw new UserError(t`bot.common.errors.no_tank_stats`);
|
2023-06-03 01:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tankStats[id];
|
|
|
|
|
}
|