2023-06-16 02:01:06 +00:00
|
|
|
import { SlashCommandBuilder } from 'discord.js';
|
2023-07-11 19:54:57 +00:00
|
|
|
import { CYCLIC_API } from '../constants/cyclic';
|
|
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
|
|
|
|
import resolveTankId from '../core/blitz/resolveTankId';
|
|
|
|
|
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
|
|
|
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
|
|
|
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
|
|
|
import interactionToURL from '../core/discord/interactionToURL';
|
|
|
|
|
import linkButton from '../core/discord/linkButton';
|
|
|
|
|
import primaryButton from '../core/discord/primaryButton';
|
|
|
|
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
|
|
|
|
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
|
|
|
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
|
|
|
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
|
|
|
|
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments';
|
|
|
|
|
import { CommandRegistry } from '../events/interactionCreate';
|
|
|
|
|
import fullStats, { StatType } from '../renderers/fullStats';
|
|
|
|
|
import { AccountInfo } from '../types/accountInfo';
|
2023-04-21 23:45:13 +00:00
|
|
|
|
2023-07-09 01:02:30 +00:00
|
|
|
export const fullStatsCommand: CommandRegistry = {
|
2023-04-26 00:02:10 +00:00
|
|
|
inProduction: true,
|
2023-07-12 18:35:31 +00:00
|
|
|
inDevelopment: false,
|
2023-04-26 00:02:10 +00:00
|
|
|
inPublic: true,
|
2023-04-22 01:18:07 +00:00
|
|
|
|
2023-06-27 02:22:28 +00:00
|
|
|
command: addStatTypeSubCommandGroups(
|
2023-06-21 01:57:27 +00:00
|
|
|
new SlashCommandBuilder()
|
2023-07-09 01:02:30 +00:00
|
|
|
.setName('fullstats')
|
2023-06-27 19:10:12 +00:00
|
|
|
.setDescription('Full in-game statistics'),
|
2023-06-21 01:57:27 +00:00
|
|
|
),
|
2023-04-22 01:18:07 +00:00
|
|
|
|
2023-06-27 01:43:30 +00:00
|
|
|
async handler(interaction) {
|
2023-06-23 01:35:15 +00:00
|
|
|
const commandGroup = interaction.options.getSubcommandGroup(
|
|
|
|
|
true,
|
|
|
|
|
) as StatType;
|
2023-06-27 02:07:14 +00:00
|
|
|
const player = await resolvePlayerFromCommand(interaction);
|
2023-07-10 01:23:49 +00:00
|
|
|
const period = resolvePeriodFromCommand(player.server, interaction);
|
2023-06-19 17:35:28 +00:00
|
|
|
const tankIdRaw = interaction.options.getString('tank')!;
|
2023-07-05 02:09:36 +00:00
|
|
|
const tankId =
|
|
|
|
|
commandGroup === 'tank' ? await resolveTankId(tankIdRaw) : null;
|
2023-06-25 02:32:56 +00:00
|
|
|
const start = interaction.options.getInteger('start');
|
|
|
|
|
const end = interaction.options.getInteger('end');
|
2023-06-28 18:45:14 +00:00
|
|
|
const path = interactionToURL(interaction, {
|
|
|
|
|
...player,
|
|
|
|
|
tankId,
|
|
|
|
|
start,
|
|
|
|
|
end,
|
|
|
|
|
});
|
|
|
|
|
const { nickname } = (
|
|
|
|
|
await getWargamingResponse<AccountInfo>(
|
|
|
|
|
`https://api.wotblitz.${player.server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
|
|
|
|
)
|
|
|
|
|
)[player.id];
|
2023-06-25 02:32:56 +00:00
|
|
|
|
|
|
|
|
return [
|
2023-07-09 01:02:30 +00:00
|
|
|
await fullStats(commandGroup, period, player, tankId),
|
2023-06-25 02:32:56 +00:00
|
|
|
primaryButton(path, 'Refresh'),
|
2023-06-28 19:27:47 +00:00
|
|
|
// linkButton(`${CYCLIC_API}/${path}`, 'Embed'),
|
2023-06-28 18:45:14 +00:00
|
|
|
linkButton(
|
|
|
|
|
`https://www.blitzstars.com/player/${player.server}/${nickname}`,
|
|
|
|
|
'BlitzStars',
|
|
|
|
|
),
|
2023-06-25 02:32:56 +00:00
|
|
|
];
|
2023-04-26 00:02:10 +00:00
|
|
|
},
|
2023-05-14 17:13:42 +00:00
|
|
|
|
2023-06-19 17:35:28 +00:00
|
|
|
autocomplete: (interaction) => {
|
2023-06-27 02:22:28 +00:00
|
|
|
autocompleteUsername(interaction);
|
|
|
|
|
autocompleteTanks(interaction);
|
2023-06-19 17:35:28 +00:00
|
|
|
},
|
2023-06-25 02:32:56 +00:00
|
|
|
|
|
|
|
|
async button(interaction) {
|
|
|
|
|
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
|
|
|
|
const path = url.pathname.split('/').filter(Boolean);
|
|
|
|
|
const commandGroup = path[1] as StatType;
|
2023-06-27 02:07:14 +00:00
|
|
|
const player = await resolvePlayerFromButton(interaction);
|
2023-07-10 01:23:49 +00:00
|
|
|
const period = resolvePeriodFromButton(player.server, interaction);
|
2023-06-25 02:32:56 +00:00
|
|
|
|
2023-07-09 01:02:30 +00:00
|
|
|
return await fullStats(
|
2023-06-25 02:32:56 +00:00
|
|
|
commandGroup,
|
|
|
|
|
period,
|
|
|
|
|
player,
|
|
|
|
|
parseInt(url.searchParams.get('tankId')!),
|
|
|
|
|
);
|
|
|
|
|
},
|
2023-07-05 01:15:18 +00:00
|
|
|
};
|