Files
blitzkit/src/commands/ownedtanks.tsx
T

114 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-05-28 16:56:15 +00:00
import { SlashCommandBuilder } from 'discord.js';
2023-06-06 16:53:13 +00:00
import NoData, { NoDataType } from '../components/NoData.js';
2023-06-05 18:47:00 +00:00
import PoweredByWargaming from '../components/PoweredByWargaming.js';
import * as Tanks from '../components/Tanks/index.js';
import TitleBar from '../components/TitleBar.js';
import Wrapper from '../components/Wrapper.js';
import { BLITZ_SERVERS } from '../constants/servers.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';
import getTankStats from '../core/blitz/getTankStats.js';
2023-05-13 22:01:58 +00:00
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
2023-06-05 18:47:00 +00:00
import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js';
2023-05-13 22:01:58 +00:00
import cmdName from '../core/interaction/cmdName.js';
2023-05-14 17:13:42 +00:00
import addUsernameOption from '../core/options/addUsernameOption.js';
2023-06-12 01:17:26 +00:00
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
2023-06-05 18:47:00 +00:00
import render from '../core/ui/render.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-06-05 18:47:00 +00:00
import { PlayerClanData } from '../types/playerClanData.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-06-06 16:50:33 +00:00
inDevelopment: true,
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')!;
const account = await getBlitzAccount(interaction);
2023-05-16 02:02:50 +00:00
const { id, server } = account;
const accountInfo = await getWargamingResponse<AccountInfo>(
2023-06-12 01:17:26 +00:00
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
2023-05-16 02:02:50 +00:00
);
const tankStats = await getTankStats(interaction, server, id);
const tanks = tankStats
2023-05-28 17:19:14 +00:00
.map((tankData) => tankopedia[tankData.tank_id])
2023-05-16 23:46:18 +00:00
.filter((tank) => tank?.tier === tier);
2023-06-05 18:47:00 +00:00
const clanData = await getWargamingResponse<PlayerClanData>(
2023-06-12 01:17:26 +00:00
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
2023-06-05 18:47:00 +00:00
);
2023-04-26 00:02:10 +00:00
2023-06-05 18:47:00 +00:00
const image = await render(
<Wrapper>
{/* TODO: integrate some of these into title bar */}
<TitleBar
name={accountInfo[id].nickname}
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier]})`}
image={
clanData[id]?.clan
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
: undefined
}
description={`Owned tanks • ${new Date().toDateString()} • ${
BLITZ_SERVERS[server]
}`}
/>
2023-06-06 16:53:13 +00:00
{tanks.length === 0 && <NoData type={NoDataType.TanksFound} />}
{tanks.length > 0 && (
<Tanks.Root>
{tanks.map((tank) => (
<Tanks.Item
key={tank.tank_id}
name={tank.name}
type={tank.type}
icon={tank.images.normal}
/>
))}
</Tanks.Root>
)}
2023-06-05 18:47:00 +00:00
<PoweredByWargaming />
</Wrapper>,
);
await interaction.editReply({ files: [image] });
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;