feat: updated /tankstats

This commit is contained in:
TresAbhi committed 2023-05-30 17:24:24 +00:00
1 parent 50369e9225
commit 831300cf69
13 files changed
+300 -272

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { go } from 'fuzzysort';
import { tankopedia, tanks } from '../blitzstars/tankopedia.js';
import errorEmbed from '../interaction/errorEmbed.js';
export default async function resolveTankId(
interaction: ChatInputCommandInteraction<CacheType>,
tank: string,
) {
const number = Number(tank);
if (Number.isNaN(number)) {
const searchResult = go(tank, tanks, { keys: ['name'], limit: 1 });
if (searchResult.length === 0) {
await interaction.editReply({
embeds: [
errorEmbed(
'Tank not found',
`Could not find tank by the name "${tank}".`,
),
],
});
throw new Error(`Tank not found by name "${tank}"`);
} else {
return searchResult[0].obj.tank_id;
}
} else {
if (tankopedia[number]) {
return number;
} else {
await interaction.editReply({
embeds: [
errorEmbed(
'Tank not found',
`Could not find tank by the ID "${number}".`,
),
],
});
throw new Error(`Tank not found by ID "${number}"`);
}
}
}