feat: user error strings

This commit is contained in:
TrèsAbhi committed 2024-03-09 11:48:35 -06:00
1 parent 265eff98bf
commit 889ae39e3b
14 files changed
+71 -374

No files matched your search

+9 -4
View File
@@ -1,18 +1,23 @@
import { Locale } from 'discord.js';
import { Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import { UserError } from '../../hooks/userError';
import { TanksStats } from '../../types/tanksStats';
import { translator } from '../localization/translator';
import fetchBlitz from './fetchBlitz';
export default async function getTankStats(region: Region, id: number) {
export default async function getTankStats(
region: Region,
id: number,
locale: Locale,
) {
const { t } = translator(locale);
const tankStats = await fetchBlitz<TanksStats>(
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
);
if (tankStats[id] === null) {
throw new UserError(
"# No tank stats available\nThis player doesn't have any stats available. This may not be the player you are looking for.",
);
throw new UserError(t`bot.common.errors.no_tank_stats`);
}
return tankStats[id];
+12 -4
View File
@@ -1,12 +1,18 @@
import { Locale } from 'discord.js';
import { go } from 'fuzzysort';
import { UserError } from '../../hooks/userError';
import markdownEscape from 'markdown-escape';
import { UserError } from '../../hooks/userError';
import {
tankDefinitions,
tanksDefinitionsArray,
} from '../blitzkrieg/tankDefinitions';
import { translator } from '../localization/translator';
export default async function resolveTankId(tank: string | number) {
export default async function resolveTankId(
tank: string | number,
locale: Locale,
) {
const { translate } = translator(locale);
const number = typeof tank === 'string' ? parseInt(tank) : tank;
if (Number.isNaN(number)) {
@@ -17,7 +23,9 @@ export default async function resolveTankId(tank: string | number) {
if (searchResult.length === 0) {
throw new UserError(
`# Tank not found\nCould not find tank by the name "${markdownEscape(`${tank}`)}".`,
translate('bot.common.errors.tank_name_not_found', [
markdownEscape(`${tank}`),
]),
);
} else {
return searchResult[0].obj.id;
@@ -27,7 +35,7 @@ export default async function resolveTankId(tank: string | number) {
return number;
} else {
throw new UserError(
`# Tank not found\nCould not find tank by the ID "${number}". Try typing the name of the tank instead of a number.`,
translate('bot.common.errors.tank_id_not_found', [`${number}`]),
);
}
}