mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: updated /tankstats
This commit is contained in:
1 parent
50369e9225
commit
831300cf69
13 files changed
+300
-272
No files matched your search
@@ -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}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user