Files
blitzkit/src/commands/tanks.ts
T

116 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-04-26 00:02:10 +00:00
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
2023-05-06 17:45:43 +00:00
import markdownEscape from 'markdown-escape';
2023-04-26 00:02:10 +00:00
import { CommandRegistry } from '../behaviors/interactionCreate.js';
2023-04-25 01:39:43 +00:00
import { SKILLED_COLOR } from '../constants/colors.js';
import { TanksStats } from '../types/tanksStats.js';
2023-05-02 23:01:54 +00:00
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
2023-04-28 13:42:42 +00:00
import { args } from '../utilities/args.js';
2023-05-08 01:03:05 +00:00
import extractUser from '../utilities/extractUser.js';
2023-04-25 01:39:43 +00:00
import getBlitzAccount from '../utilities/getBlitzAccount.js';
2023-04-27 00:21:39 +00:00
import getWargamingResponse from '../utilities/getWargamingResponse.js';
2023-04-27 19:55:42 +00:00
import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js';
2023-04-28 13:07:51 +00:00
const COMP_TANKS = [
2023-04-27 19:55:42 +00:00
// light tanks
2023-04-28 13:07:51 +00:00
24321, // t-100 lt
20257, // sheridan
3649, // bat chat
19537, // vickers
2023-04-27 19:55:42 +00:00
// heavy tanks
2023-04-28 13:07:51 +00:00
6145, // is-4
7169, // is-7
10785, // t110e5
12161, // strvk
4481, // kranvagn
22817, // m6 yoh
6225, // fv215b
5425, // wz 113
7297, // 60tp
58641, // vk 72
6753, // type 71
];
2023-04-25 01:39:43 +00:00
2023-04-26 00:02:10 +00:00
export default {
inProduction: true,
2023-04-28 13:42:42 +00:00
inDevelopment: false,
2023-04-26 00:02:10 +00:00
inPublic: true,
2023-04-25 01:39:43 +00:00
2023-04-26 00:02:10 +00:00
command: new SlashCommandBuilder()
2023-05-07 20:17:52 -05:00
.setName('tanks')
2023-04-26 00:02:10 +00:00
.setDescription("Shows a player's owned tanks")
2023-05-02 23:01:54 +00:00
.addIntegerOption((option) =>
2023-04-26 00:02:10 +00:00
option
.setName('tier')
2023-05-08 01:03:05 +00:00
.setDescription('The tier you want to see')
2023-04-26 00:02:10 +00:00
.setMinValue(1)
.setMaxValue(10)
.setRequired(true),
2023-05-08 01:03:05 +00:00
)
.addStringOption(addServerChoices)
.addStringOption(addIGNOption),
2023-04-25 01:39:43 +00:00
2023-05-08 01:03:05 +00:00
async execute(interaction) {
2023-05-02 23:01:54 +00:00
const tier = interaction.options.getInteger('tier')!;
2023-05-08 01:03:05 +00:00
await interaction.deferReply();
const extractedUser = await extractUser(interaction);
if (!extractedUser) return;
const { name, server } = extractedUser;
2023-05-06 18:03:37 +00:00
const command = `tanks ${server} ${name} ${tier}`;
2023-04-25 01:39:43 +00:00
2023-05-06 18:03:37 +00:00
getBlitzAccount(interaction, command, name, server, async (account) => {
2023-04-27 00:21:39 +00:00
getWargamingResponse<TanksStats>(
2023-04-28 13:42:42 +00:00
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}`,
2023-04-27 00:21:39 +00:00
interaction,
2023-05-06 18:03:37 +00:00
command,
2023-04-27 00:21:39 +00:00
async (tankStats) => {
2023-05-08 01:03:05 +00:00
const tanks = tankStats[account.account_id]
.map((tankData) => tankopedia.data[tankData.tank_id])
.filter((tank) => tank.tier === tier);
2023-04-26 00:02:10 +00:00
2023-04-27 01:13:50 +00:00
await interaction.editReply({
2023-04-27 00:21:39 +00:00
embeds: [
new EmbedBuilder()
.setTitle(
2023-05-06 17:45:43 +00:00
`${markdownEscape(account.nickname)}'s owned ${
2023-04-27 00:21:39 +00:00
tier === null ? '' : `tier ${tier} `
}tanks`,
)
.setDescription(
2023-04-27 19:55:42 +00:00
`${
tanks.length === 0
2023-05-06 17:45:43 +00:00
? `No tanks found in tier ${tier}`
2023-04-27 19:55:42 +00:00
: tanks
.map(
(tank) =>
2023-05-06 17:45:43 +00:00
`${TANK_TYPE_EMOJIS[tank.type]} ${markdownEscape(
tank.name,
)} ${tank.is_premium ? '⭐' : ''}${
2023-04-28 13:07:51 +00:00
COMP_TANKS.includes(tank.tank_id) ? '🏆' : ''
2023-04-27 19:55:42 +00:00
}`,
)
.join('\n')
}\n\n**Legend**\n⭐ = Premium/Collector\n${
tier === 10 ? '🏆 = Comp Tank\n' : ''
}${TANK_TYPE_EMOJIS.heavyTank} = Heavy\n${
TANK_TYPE_EMOJIS.mediumTank
} = Medium\n${TANK_TYPE_EMOJIS.lightTank} = Light\n${
TANK_TYPE_EMOJIS['AT-SPG']
} = Tank Destroyer`,
2023-04-27 00:21:39 +00:00
)
.setColor(SKILLED_COLOR),
],
});
2023-04-26 00:02:10 +00:00
2023-04-27 00:21:39 +00:00
console.log(
`Displaying ${account.nickname}'s owned tanks in tier ${tier}`,
);
},
2023-04-26 14:23:42 +00:00
);
2023-04-25 01:39:43 +00:00
});
2023-04-26 00:02:10 +00:00
},
} satisfies CommandRegistry;