mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: better error handling
This commit is contained in:
1 parent
c494331470
commit
48241bd0d4
12 files changed
+347
-106
No files matched your search
@@ -7,6 +7,7 @@ import fetch from 'node-fetch';
|
||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { Player, Players } from '../types/players.js';
|
||||
import wargamingError from './wargamingError.js';
|
||||
|
||||
export default async function getBlitzAccount(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
@@ -19,37 +20,37 @@ export default async function getBlitzAccount(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${name}`,
|
||||
).then((response) => response.json())) as Players;
|
||||
|
||||
if (
|
||||
players.status === 'ok' &&
|
||||
players.data.length > 0 &&
|
||||
players.data[0].nickname === name
|
||||
) {
|
||||
callback(players.data[0]);
|
||||
} else {
|
||||
// no exact match
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`Account not found`)
|
||||
.setDescription(
|
||||
`I couldn't find "${name}" in the ${serverName} server. I found ${
|
||||
players?.data
|
||||
? players.data.length < 100
|
||||
? players.data.length
|
||||
: 'over 100'
|
||||
: 0
|
||||
} similarly spelled account${
|
||||
players?.data?.length !== 1 ? 's' : ''
|
||||
}. ${
|
||||
players?.data && players.data.length > 0
|
||||
? `Did you mean "${players.data[0].nickname}"? `
|
||||
: ''
|
||||
}Re-run the command, don't make typos, and capitalize correctly.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
if (players.status === 'ok') {
|
||||
if (players.data.length > 0 && players.data[0].nickname === name) {
|
||||
callback(players.data[0]);
|
||||
} else {
|
||||
// no exact match
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`Account not found`)
|
||||
.setDescription(
|
||||
`I couldn't find "${name}" in the ${serverName} server. I found ${
|
||||
players?.data
|
||||
? players.data.length < 100
|
||||
? players.data.length
|
||||
: 'over 100'
|
||||
: 0
|
||||
} similarly spelled account${
|
||||
players?.data?.length !== 1 ? 's' : ''
|
||||
}. ${
|
||||
players?.data && players.data.length > 0
|
||||
? `Did you mean "${players.data[0].nickname}"? `
|
||||
: ''
|
||||
}Re-run the command, don't make typos, and capitalize correctly.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Account not found for ${name} in ${serverName} server.`);
|
||||
console.log(`Account not found for ${name} in ${serverName} server.`);
|
||||
}
|
||||
} else {
|
||||
wargamingError(interaction);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
import { argv } from 'process';
|
||||
|
||||
const isDevBoolean = argv.includes('--dev');
|
||||
const isDevBoolean = process.argv.includes('--dev');
|
||||
|
||||
export default function isDev() {
|
||||
return isDevBoolean;
|
||||
|
||||
Reference in new issue
Block a user