mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-12 20:26:10 +01:00
feat: user error strings
This commit is contained in:
1 parent
265eff98bf
commit
889ae39e3b
14 files changed
+71
-374
No files matched your search
@@ -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}`]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user