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-28 18:07:49 +00:00
|
|
|
import PoweredBy, { PoweredByType } from '../components/PoweredBy.js';
|
2023-06-05 18:47:00 +00:00
|
|
|
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-06-03 01:19:52 +00:00
|
|
|
import getTankStats from '../core/blitz/getTankStats.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
2023-06-21 01:52:26 +00:00
|
|
|
import {
|
|
|
|
|
TIER_ROMAN_NUMERALS,
|
|
|
|
|
Tier,
|
|
|
|
|
tankopedia,
|
|
|
|
|
} from '../core/blitz/tankopedia.js';
|
2023-06-27 02:22:28 +00:00
|
|
|
import addUsernameChoices from '../core/discord/addUsernameChoices.js';
|
|
|
|
|
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
|
2023-06-27 02:07:14 +00:00
|
|
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
|
2023-06-27 17:22:27 +00:00
|
|
|
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
|
2023-06-25 02:32:56 +00:00
|
|
|
import { CommandRegistry } from '../events/interactionCreate/index.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-07-05 01:15:18 +00:00
|
|
|
export const ownedTanksCommand: CommandRegistry = {
|
2023-04-26 00:02:10 +00:00
|
|
|
inProduction: true,
|
2023-06-23 17:14:27 +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-06-21 02:01:12 +00:00
|
|
|
.setName('ownedtanks')
|
2023-04-26 00:02:10 +00:00
|
|
|
.setDescription("Shows a player's owned tanks")
|
2023-06-16 02:07:01 +00:00
|
|
|
.addStringOption((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-06-16 02:07:01 +00:00
|
|
|
.setChoices(
|
|
|
|
|
{ name: 'Tier I', value: '1' },
|
|
|
|
|
{ name: 'Tier II', value: '2' },
|
|
|
|
|
{ name: 'Tier III', value: '3' },
|
|
|
|
|
{ name: 'Tier IV', value: '4' },
|
|
|
|
|
{ name: 'Tier V', value: '5' },
|
|
|
|
|
{ name: 'Tier VI', value: '6' },
|
|
|
|
|
{ name: 'Tier VII', value: '7' },
|
|
|
|
|
{ name: 'Tier VIII', value: '8' },
|
|
|
|
|
{ name: 'Tier IX', value: '9' },
|
|
|
|
|
{ name: 'Tier X', value: '10' },
|
|
|
|
|
)
|
2023-04-26 00:02:10 +00:00
|
|
|
.setRequired(true),
|
2023-05-08 01:03:05 +00:00
|
|
|
)
|
2023-06-27 02:22:28 +00:00
|
|
|
.addStringOption(addUsernameChoices),
|
2023-04-25 01:39:43 +00:00
|
|
|
|
2023-06-27 01:43:30 +00:00
|
|
|
async handler(interaction) {
|
2023-06-16 02:07:01 +00:00
|
|
|
const tier = Number(interaction.options.getString('tier'));
|
2023-06-27 02:07:14 +00:00
|
|
|
const account = await resolvePlayerFromCommand(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
|
|
|
);
|
2023-06-18 01:56:21 +00:00
|
|
|
const tankStats = await getTankStats(server, id);
|
2023-06-03 01:19:52 +00:00
|
|
|
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-16 02:01:06 +00:00
|
|
|
return (
|
2023-06-05 18:47:00 +00:00
|
|
|
<Wrapper>
|
|
|
|
|
{/* TODO: integrate some of these into title bar */}
|
|
|
|
|
<TitleBar
|
|
|
|
|
name={accountInfo[id].nickname}
|
2023-06-21 01:52:26 +00:00
|
|
|
nameDiscriminator={`(Tier ${TIER_ROMAN_NUMERALS[tier as Tier]})`}
|
2023-06-05 18:47:00 +00:00
|
|
|
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
|
|
|
|
2023-06-28 18:07:49 +00:00
|
|
|
<PoweredBy type={PoweredByType.Wargaming} />
|
2023-06-16 02:01:06 +00:00
|
|
|
</Wrapper>
|
2023-06-05 18:47:00 +00:00
|
|
|
);
|
2023-04-26 00:02:10 +00:00
|
|
|
},
|
2023-05-14 17:13:42 +00:00
|
|
|
|
2023-06-27 02:22:28 +00:00
|
|
|
autocomplete: autocompleteUsername,
|
2023-07-05 01:15:18 +00:00
|
|
|
};
|