mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-13 20:56:11 +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
@@ -15,6 +15,9 @@ export async function getFiltersFromCommand(
|
||||
treeType:
|
||||
(interaction.options.getString('tree-type') as TreeType | undefined) ??
|
||||
undefined,
|
||||
tank: tankRaw === null ? undefined : await resolveTankId(tankRaw),
|
||||
tank:
|
||||
tankRaw === null
|
||||
? undefined
|
||||
: await resolveTankId(tankRaw, interaction.locale),
|
||||
} satisfies StatFilters;
|
||||
}
|
||||
@@ -3,11 +3,13 @@ import markdownEscape from 'markdown-escape';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { UserError } from '../../hooks/userError';
|
||||
import searchClansAcrossRegions from '../blitz/searchClansAcrossRegions';
|
||||
import { translator } from '../localization/translator';
|
||||
import { serverAndIdPattern } from './resolvePlayerFromCommand';
|
||||
|
||||
export default async function resolveClanFromCommand(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
) {
|
||||
const { translate } = translator(interaction.locale);
|
||||
const clan = interaction.options.getString('clan', true);
|
||||
|
||||
if (serverAndIdPattern.test(clan)) {
|
||||
@@ -20,7 +22,7 @@ export default async function resolveClanFromCommand(
|
||||
return { region: accounts[0].region, id: accounts[0].clan_id };
|
||||
} else {
|
||||
throw new UserError(
|
||||
`# Could not find clan\nCouldn't find "${markdownEscape(clan)}". Try selecting a clan from the search result.`,
|
||||
translate('bot.common.errors.clan_not_found', [markdownEscape(clan)]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Region } from '../../constants/regions';
|
||||
import { UserError } from '../../hooks/userError';
|
||||
import searchPlayersAcrossRegions from '../blitz/searchPlayersAcrossRegions';
|
||||
import { getBlitzFromDiscord } from '../blitzkrieg/discordBlitz';
|
||||
import { translator } from '../localization/translator';
|
||||
|
||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
|
||||
@@ -15,6 +16,7 @@ export interface ResolvedPlayer {
|
||||
export default async function resolvePlayerFromCommand(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
const { t, translate } = translator(interaction.locale);
|
||||
const commandUsername = interaction.options.getString('username');
|
||||
|
||||
if (commandUsername) {
|
||||
@@ -35,9 +37,9 @@ export default async function resolvePlayerFromCommand(
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
throw new UserError(
|
||||
`# Could not find user\nI couldn't find user "${markdownEscape(
|
||||
commandUsername,
|
||||
)}". Try picking an user from the search result, typing in a valid username, or using the \`/link\` command.`,
|
||||
translate('bot.common.errors.player_not_found', [
|
||||
markdownEscape(commandUsername),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -47,9 +49,7 @@ export default async function resolvePlayerFromCommand(
|
||||
if (account) {
|
||||
return { region: account.region, id: account.blitz };
|
||||
} else {
|
||||
throw new UserError(
|
||||
"# I don't know who you are\nUse the `/link` command to get started.",
|
||||
);
|
||||
throw new UserError(t`bot.common.errors.player_not_linked`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user