Files
blitzkit/src/commands/ownedtanks.ts
T

113 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-05-21 16:50:05 +00:00
import { INFO_COLOR } from '../constants/colors.js';
2023-05-14 17:13:42 +00:00
import usernameAutocomplete from '../core/autocomplete/username.js';
2023-05-16 02:02:50 +00:00
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
2023-05-13 22:01:58 +00:00
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitzstars/tankopedia.js';
import cmdName from '../core/interaction/cmdName.js';
2023-05-14 17:13:42 +00:00
import addUsernameOption from '../core/options/addUsernameOption.js';
2023-05-13 22:01:58 +00:00
import { args } from '../core/process/args.js';
2023-05-19 23:50:24 +00:00
import { CommandRegistry } from '../events/interactionCreate.js';
2023-05-16 02:02:50 +00:00
import { AccountInfo } from '../types/accountInfo.js';
2023-04-25 01:39:43 +00:00
import { TanksStats } from '../types/tanksStats.js';
2023-05-13 22:01:58 +00:00
import resolveTankName from '../utilities/resolveTankName.js';
2023-04-27 19:55:42 +00:00
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-05-16 02:02:50 +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-16 23:46:18 +00:00
.setName(cmdName('ownedtanks'))
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
)
2023-05-14 17:13:42 +00:00
.addStringOption(addUsernameOption),
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-14 17:13:42 +00:00
const name = interaction.options.getString('username')!;
2023-05-16 02:02:50 +00:00
const account = await getBlitzAccount(interaction, name);
2023-05-08 01:45:57 +00:00
if (!account) return;
2023-05-16 02:02:50 +00:00
const { id, server } = account;
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
);
if (!accountInfo) return;
2023-05-08 01:45:57 +00:00
const tankStats = await getWargamingResponse<TanksStats>(
2023-05-16 02:02:50 +00:00
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
2023-05-08 01:45:57 +00:00
);
2023-05-13 22:01:58 +00:00
if (!tankStats) return;
2023-05-16 02:02:50 +00:00
const tanks = tankStats[id]
2023-05-08 01:45:57 +00:00
.map((tankData) => tankopedia.data[tankData.tank_id])
2023-05-16 23:46:18 +00:00
.filter((tank) => tank?.tier === tier);
2023-04-26 00:02:10 +00:00
2023-05-08 01:45:57 +00:00
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
2023-05-16 02:02:50 +00:00
`${markdownEscape(accountInfo[id].nickname)}'s owned ${
2023-05-08 01:45:57 +00:00
tier === null ? '' : `tier ${tier} `
}tanks`,
)
.setDescription(
`${
tanks.length === 0
? `No tanks found in tier ${tier}`
: tanks
.map(
(tank) =>
2023-05-13 22:01:58 +00:00
`${TANK_TYPE_EMOJIS[tank.type]} ${resolveTankName(
tank,
2023-05-08 01:45:57 +00:00
)} ${tank.is_premium ? '⭐' : ''}${
COMP_TANKS.includes(tank.tank_id) ? '🏆' : ''
}`,
)
.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-05-21 16:50:05 +00:00
.setColor(INFO_COLOR),
2023-05-08 01:45:57 +00:00
],
2023-04-25 01:39:43 +00:00
});
2023-05-08 01:45:57 +00:00
2023-05-16 02:02:50 +00:00
console.log(
`Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`,
);
2023-04-26 00:02:10 +00:00
},
2023-05-14 17:13:42 +00:00
autocomplete: usernameAutocomplete,
2023-04-26 00:02:10 +00:00
} satisfies CommandRegistry;