feat: no embed errors

This commit is contained in:
TrèsAbhi committed 2024-01-21 18:29:32 -06:00
1 parent 6094875ffb
commit 8946f115c0
8 files changed
+15 -33

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "blitzkrieg",
"version": "1.15.10",
"version": "1.15.11",
"description": "🎉 Tools for everything World of Tanks Blitz",
"main": "src/server.ts",
"type": "module",
+2 -2
View File
@@ -4,6 +4,7 @@ import {
SlashCommandSubcommandBuilder,
} from 'discord.js';
import { range } from 'lodash';
import markdownEscape from 'markdown-escape';
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
import * as Leaderboard from '../components/Leaderboard';
import TitleBar from '../components/TitleBar';
@@ -337,8 +338,7 @@ export const ratingsCommand = new Promise<CommandRegistryPromisable>(
if (playerIndex === -1) {
throw new UserError(
`${accountInfo.nickname} didn't play ratings in season ${season}`,
'This player did not participate in this season or did not get past calibration.',
`# ${markdownEscape(accountInfo.nickname)} didn't play ratings in season ${season}\nThis player did not participate in this season or did not get past calibration.`,
);
}
+1 -2
View File
@@ -11,8 +11,7 @@ export default async function getTankStats(region: Region, id: number) {
if (tankStats[id] === null) {
throw new UserError(
'No tank stats available',
"This player doesn't have any stats available. This may not be the player you are looking for.",
"# No tank stats available\nThis player doesn't have any stats available. This may not be the player you are looking for.",
);
}
+3 -4
View File
@@ -1,4 +1,5 @@
import { go } from 'fuzzysort';
import markdownEscape from 'markdown-escape';
import {
tankDefinitions,
tanksDefinitionsArray,
@@ -16,8 +17,7 @@ export default async function resolveTankId(tank: string | number) {
if (searchResult.length === 0) {
throw new UserError(
'Tank not found',
`Could not find tank by the name "${tank}".`,
`# Tank not found\nCould not find tank by the name "${markdownEscape(tank)}".`,
);
} else {
return searchResult[0].obj.id;
@@ -27,8 +27,7 @@ export default async function resolveTankId(tank: string | number) {
return number;
} else {
throw new UserError(
'Tank not found',
`Could not find tank by the ID "${number}". Try typing the name of the tank instead of a number.`,
`# Tank not found\nCould not find tank by the ID "${number}". Try typing the name of the tank instead of a number.`,
);
}
}
+1 -4
View File
@@ -2,8 +2,5 @@
* Discriminator for user caused errors to not report in logs
*/
export class UserError {
constructor(
public message: string,
public cause: string,
) {}
constructor(public message: string) {}
}
+2 -2
View File
@@ -1,4 +1,5 @@
import { ChatInputCommandInteraction } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { Region } from '../../constants/regions';
import searchClansAcrossRegions from '../blitz/searchClansAcrossRegions';
import { UserError } from '../blitzkrieg/userError';
@@ -19,8 +20,7 @@ export default async function resolveClanFromCommand(
return { region: accounts[0].region, id: accounts[0].clan_id };
} else {
throw new UserError(
'Could not find clan',
`\`${clan}\` was not found. Try selecting a clan from the search result.`,
`# Could not find clan\nCouldn't find "${markdownEscape(clan)}". Try selecting a clan from the search result.`,
);
}
}
+2 -4
View File
@@ -35,8 +35,7 @@ export default async function resolvePlayerFromCommand(
} satisfies ResolvedPlayer;
} else {
throw new UserError(
'Could not find user',
`I couldn't find user "${markdownEscape(
`# 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.`,
);
@@ -49,8 +48,7 @@ export default async function resolvePlayerFromCommand(
return { region: account.region, id: account.blitz };
} else {
throw new UserError(
"You're account isn't linked with Blitzkrieg yet",
'Use the `/link` command to get started.',
"# I don't know who you are\nUse the `/link` command to get started.",
);
}
}
@@ -11,7 +11,6 @@ import { commands } from '..';
import discord from '../../../../discord.json' assert { type: 'json' };
import { UserError } from '../../../core/blitzkrieg/userError';
import buttonLink from '../../../core/discord/buttonLink';
import embedNegative from '../../../core/discord/embedNegative';
import embedWarning from '../../../core/discord/embedWarning';
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable';
import { psa } from '../../../core/discord/psa';
@@ -119,25 +118,15 @@ export default async function handleChatInputCommand(
if (error instanceof UserError) {
interaction.editReply({
embeds: [
embedNegative(
error.message,
(error.cause as string | undefined) ??
'No further information is available.',
),
],
content: error.message,
components,
});
} else {
console.error(interaction.commandName, error);
interaction.editReply({
embeds: [
embedNegative(
'Blitzkrieg ran into an error!',
"We're so sorry about this. Feel free to [join the official Discord server](https://discord.gg/nDt7AjGJQH) to get help.",
),
],
content:
"# Blitzkrieg ran into an error!\nWe're so sorry about this. Feel free to [join the official Discord server](https://discord.gg/nDt7AjGJQH) to get help.",
components,
});
}