2024-01-19 21:32:46 -06:00
|
|
|
import { SlashCommandBuilder } from 'discord.js';
|
|
|
|
|
import { encyclopediaInfo } from '../core/blitz/encyclopediaInfo';
|
|
|
|
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
|
|
|
|
import { addFilterOptions } from '../core/discord/addFilterOptions';
|
|
|
|
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
|
|
|
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
|
|
|
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
|
|
|
|
import buttonPrimary from '../core/discord/buttonPrimary';
|
|
|
|
|
import commandToURL from '../core/discord/commandToURL';
|
|
|
|
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
|
|
|
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
|
|
|
|
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
|
|
|
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
|
|
|
|
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand';
|
|
|
|
|
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
|
|
|
|
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
2024-03-06 15:34:10 -06:00
|
|
|
import { CommandRegistry } from '../events/interactionCreate';
|
2024-01-19 21:32:46 -06:00
|
|
|
import { renderBreakdown } from './breakdown';
|
|
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
|
|
|
|
const awaitedEncyclopediaInfo = await encyclopediaInfo;
|
|
|
|
|
const command = addFilterOptions(
|
|
|
|
|
new SlashCommandBuilder()
|
|
|
|
|
.setName('today')
|
|
|
|
|
.setDescription("Today's played tanks and statistics"),
|
|
|
|
|
awaitedEncyclopediaInfo,
|
|
|
|
|
).addStringOption(addUsernameChoices);
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
resolve({
|
|
|
|
|
inProduction: true,
|
|
|
|
|
inPublic: true,
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
command,
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
async handler(interaction) {
|
|
|
|
|
const player = await resolvePlayerFromCommand(interaction);
|
|
|
|
|
const period = resolvePeriodFromCommand(
|
|
|
|
|
player.region,
|
|
|
|
|
interaction,
|
|
|
|
|
'today',
|
|
|
|
|
);
|
|
|
|
|
const filters = await getFiltersFromCommand(interaction);
|
|
|
|
|
const path = commandToURL(interaction, {
|
|
|
|
|
...player,
|
|
|
|
|
...getCustomPeriodParams(interaction, true),
|
|
|
|
|
...filters,
|
|
|
|
|
});
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
return [
|
|
|
|
|
...(await renderBreakdown(player, period, filters)),
|
|
|
|
|
buttonPrimary(path, 'Refresh'),
|
|
|
|
|
await getBlitzStarsLinkButton(player.region, player.id),
|
|
|
|
|
];
|
|
|
|
|
},
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
autocomplete: (interaction) => {
|
|
|
|
|
autocompleteUsername(interaction);
|
|
|
|
|
autocompleteTanks(interaction);
|
|
|
|
|
},
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
async button(interaction) {
|
|
|
|
|
const player = await resolvePlayerFromButton(interaction);
|
|
|
|
|
const period = resolvePeriodFromButton(player.region, interaction);
|
|
|
|
|
const filters = getFiltersFromButton(interaction);
|
2024-01-19 21:32:46 -06:00
|
|
|
|
2024-03-06 15:34:10 -06:00
|
|
|
return await renderBreakdown(player, period, filters);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|