mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: express responses
This commit is contained in:
1 parent
0f46f333b5
commit
f2ae698438
45 files changed
+153
-93
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { Client, GatewayIntentBits } from 'discord.js';
|
import { Client, GatewayIntentBits } from 'discord.js';
|
||||||
import { DISCORD_TOKEN } from './core/process/args.js';
|
import { DISCORD_TOKEN } from './core/node/args.js';
|
||||||
import { registerErrorHandlers } from './events/error.js';
|
import { registerErrorHandlers } from './events/error.js';
|
||||||
import guildMemberAdd from './events/guildMemberAdd.js';
|
import guildMemberAdd from './events/guildMemberAdd.js';
|
||||||
import interactionCreate from './events/interactionCreate/index.js';
|
import interactionCreate from './events/interactionCreate/index.js';
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { tankopedia } from '../core/blitz/tankopedia.js';
|
|||||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||||
import cleanTable from '../core/interaction/cleanTable.js';
|
import cleanTable from '../core/interaction/cleanTable.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
import getClientId from '../core/process/getClientId.js';
|
import getClientId from '../core/node/getClientId.js';
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
|
|
||||||
const executionStart = new Date().getTime();
|
const executionStart = new Date().getTime();
|
||||||
@@ -19,7 +19,7 @@ export default {
|
|||||||
.setName('debug')
|
.setName('debug')
|
||||||
.setDescription('Debug information about the bot'),
|
.setDescription('Debug information about the bot'),
|
||||||
|
|
||||||
execute(interaction) {
|
handler(interaction) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const uptime = currentTime - executionStart;
|
const uptime = currentTime - executionStart;
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
|||||||
import cleanTable, { TableInput } from '../core/interaction/cleanTable.js';
|
import cleanTable, { TableInput } from '../core/interaction/cleanTable.js';
|
||||||
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||||
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export default {
|
|||||||
)
|
)
|
||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const clan = interaction.options.getString('clan') as SkilledClan;
|
const clan = interaction.options.getString('clan') as SkilledClan;
|
||||||
const { id, server } = await resolvePlayer(interaction);
|
const { id, server } = await resolvePlayer(interaction);
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { SlashCommandBuilder } from 'discord.js';
|
|||||||
import tanksAutocomplete from '../core/autocomplete/tanks.js';
|
import tanksAutocomplete from '../core/autocomplete/tanks.js';
|
||||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||||
import resolveTankId from '../core/blitz/resolveTankId.js';
|
import resolveTankId from '../core/blitz/resolveTankId.js';
|
||||||
|
import resolvePeriodFromCommand from '../core/interaction/resolvePeriodFromCommand.js';
|
||||||
import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
|
import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
|
||||||
import resolvePeriod from '../core/options/resolvePeriod.js';
|
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import evolution from '../renderers/evolution.js';
|
import evolution from '../renderers/evolution.js';
|
||||||
@@ -20,12 +20,12 @@ export default {
|
|||||||
.setDescription('Evolution of statistics'),
|
.setDescription('Evolution of statistics'),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup = interaction.options.getSubcommandGroup(
|
const commandGroup = interaction.options.getSubcommandGroup(
|
||||||
true,
|
true,
|
||||||
) as StatType;
|
) as StatType;
|
||||||
const player = await resolvePlayer(interaction);
|
const player = await resolvePlayer(interaction);
|
||||||
const period = resolvePeriod(interaction);
|
const period = resolvePeriodFromCommand(interaction);
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
const tankIdRaw = interaction.options.getString('tank')!;
|
||||||
const tankId = commandGroup === 'tank' ? resolveTankId(tankIdRaw) : 0;
|
const tankId = commandGroup === 'tank' ? resolveTankId(tankIdRaw) : 0;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default {
|
|||||||
.setName('help')
|
.setName('help')
|
||||||
.setDescription('All the help you need about the bot'),
|
.setDescription('All the help you need about the bot'),
|
||||||
|
|
||||||
execute(interaction) {
|
handler(interaction) {
|
||||||
return infoEmbed(
|
return infoEmbed(
|
||||||
`${client.user?.username} help`,
|
`${client.user?.username} help`,
|
||||||
`**About**\n${
|
`**About**\n${
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import { BLITZ_SERVERS } from '../constants/servers.js';
|
|||||||
import clanAutocomplete from '../core/autocomplete/clan.js';
|
import clanAutocomplete from '../core/autocomplete/clan.js';
|
||||||
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addClanChoices from '../core/options/addClanChoices.js';
|
import addClanChoices from '../core/options/addClanChoices.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
import { ClanInfo } from '../types/clanInfo.js';
|
import { ClanInfo } from '../types/clanInfo.js';
|
||||||
@@ -34,7 +34,7 @@ export default {
|
|||||||
.setMinValue(0),
|
.setMinValue(0),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const clanName = interaction.options.getString('clan')!;
|
const clanName = interaction.options.getString('clan')!;
|
||||||
const { server, id } = await getBlitzClan(interaction, clanName);
|
const { server, id } = await getBlitzClan(interaction, clanName);
|
||||||
const threshold =
|
const threshold =
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import {
|
|||||||
Tier,
|
Tier,
|
||||||
tankopedia,
|
tankopedia,
|
||||||
} from '../core/blitz/tankopedia.js';
|
} from '../core/blitz/tankopedia.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
import { PlayerClanData } from '../types/playerClanData.js';
|
import { PlayerClanData } from '../types/playerClanData.js';
|
||||||
@@ -69,7 +69,7 @@ export default {
|
|||||||
)
|
)
|
||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const tier = Number(interaction.options.getString('tier'));
|
const tier = Number(interaction.options.getString('tier'));
|
||||||
const account = await resolvePlayer(interaction);
|
const account = await resolvePlayer(interaction);
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default {
|
|||||||
option.setName('blitz').setDescription('Ping Blitz'),
|
option.setName('blitz').setDescription('Ping Blitz'),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const subcommand = interaction.options.getSubcommand();
|
const subcommand = interaction.options.getSubcommand();
|
||||||
const executionStart = Date.now();
|
const executionStart = Date.now();
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import usernameAutocomplete from '../core/autocomplete/username.js';
|
|||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js';
|
import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountAchievements } from '../types/accountAchievements.js';
|
import { AccountAchievements } from '../types/accountAchievements.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
@@ -33,7 +33,7 @@ export default {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
const sortBy = (interaction.options.getString('sort') ?? 'name') as SortBy;
|
||||||
const account = await resolvePlayer(interaction);
|
const account = await resolvePlayer(interaction);
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import usernameAutocomplete from '../core/autocomplete/username.js';
|
|||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import cleanTable from '../core/interaction/cleanTable.js';
|
import cleanTable from '../core/interaction/cleanTable.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
.setDescription('Basic information about a player')
|
.setDescription('Basic information about a player')
|
||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const account = await resolvePlayer(interaction);
|
const account = await resolvePlayer(interaction);
|
||||||
const { id, server } = account;
|
const { id, server } = account;
|
||||||
const accounts = await getWargamingResponse<AccountInfo>(
|
const accounts = await getWargamingResponse<AccountInfo>(
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import markdownEscape from 'markdown-escape';
|
|||||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addClanChoices from '../core/options/addClanChoices.js';
|
import addClanChoices from '../core/options/addClanChoices.js';
|
||||||
import addServerChoices from '../core/options/addServerChoices.js';
|
import addServerChoices from '../core/options/addServerChoices.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { ClanList } from '../types/clanList.js';
|
import { ClanList } from '../types/clanList.js';
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ export default {
|
|||||||
.setMaxValue(100),
|
.setMaxValue(100),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const server = interaction.options.getString('server') as BlitzServer;
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
const clan = interaction.options.getString('clan')!;
|
const clan = interaction.options.getString('clan')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
|||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import { usernamePattern } from '../core/blitz/listAccountsPanServer.js';
|
import { usernamePattern } from '../core/blitz/listAccountsPanServer.js';
|
||||||
import infoEmbed from '../core/interaction/infoEmbed.js';
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addServerChoices from '../core/options/addServerChoices.js';
|
import addServerChoices from '../core/options/addServerChoices.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountList } from '../types/accountList.js';
|
import { AccountList } from '../types/accountList.js';
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ export default {
|
|||||||
.setMaxValue(100),
|
.setMaxValue(100),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const server = interaction.options.getString('server') as BlitzServer;
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
const name = interaction.options.getString('username')!;
|
const name = interaction.options.getString('username')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default {
|
|||||||
.setMaxValue(100),
|
.setMaxValue(100),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const tank = interaction.options.getString('tank')!;
|
const tank = interaction.options.getString('tank')!;
|
||||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||||
const results = go(tank, TANK_NAMES, { limit }).map(
|
const results = go(tank, TANK_NAMES, { limit }).map(
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import resolveTankId from '../core/blitz/resolveTankId.js';
|
|||||||
import interactionToURL from '../core/interaction/interactionToURL.js';
|
import interactionToURL from '../core/interaction/interactionToURL.js';
|
||||||
import linkButton from '../core/interaction/linkButton.js';
|
import linkButton from '../core/interaction/linkButton.js';
|
||||||
import primaryButton from '../core/interaction/primaryButton.js';
|
import primaryButton from '../core/interaction/primaryButton.js';
|
||||||
|
import resolvePeriodFromCommand from '../core/interaction/resolvePeriodFromCommand.js';
|
||||||
import { Period } from '../core/options/addPeriodSubCommands.js';
|
import { Period } from '../core/options/addPeriodSubCommands.js';
|
||||||
import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
|
import addStatsSubCommandGroups from '../core/options/addStatsSubCommandGroups.js';
|
||||||
import resolvePeriod from '../core/options/resolvePeriod.js';
|
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import stats, { StatType } from '../renderers/stats.js';
|
import stats, { StatType } from '../renderers/stats.js';
|
||||||
@@ -24,13 +24,13 @@ export default {
|
|||||||
.setDescription('In-game statistics'),
|
.setDescription('In-game statistics'),
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const commandGroup = interaction.options.getSubcommandGroup(
|
const commandGroup = interaction.options.getSubcommandGroup(
|
||||||
true,
|
true,
|
||||||
) as StatType;
|
) as StatType;
|
||||||
const subcommand = interaction.options.getSubcommand() as Period;
|
const subcommand = interaction.options.getSubcommand() as Period;
|
||||||
const player = await resolvePlayer(interaction);
|
const player = await resolvePlayer(interaction);
|
||||||
const period = resolvePeriod(interaction);
|
const period = resolvePeriodFromCommand(interaction);
|
||||||
const tankIdRaw = interaction.options.getString('tank')!;
|
const tankIdRaw = interaction.options.getString('tank')!;
|
||||||
const tankId = commandGroup === 'tank' ? resolveTankId(tankIdRaw) : 0;
|
const tankId = commandGroup === 'tank' ? resolveTankId(tankIdRaw) : 0;
|
||||||
const start = interaction.options.getInteger('start');
|
const start = interaction.options.getInteger('start');
|
||||||
@@ -57,7 +57,7 @@ export default {
|
|||||||
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
const url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
const path = url.pathname.split('/').filter(Boolean);
|
||||||
const commandGroup = path[1] as StatType;
|
const commandGroup = path[1] as StatType;
|
||||||
const period = resolvePeriod(interaction);
|
const period = resolvePeriodFromCommand(interaction);
|
||||||
const player = await resolvePlayer(interaction);
|
const player = await resolvePlayer(interaction);
|
||||||
|
|
||||||
return await stats(
|
return await stats(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export default {
|
|||||||
.setDescription('A general daily breakdown of your performance')
|
.setDescription('A general daily breakdown of your performance')
|
||||||
.addStringOption(addUsernameOption),
|
.addStringOption(addUsernameOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const player = await resolvePlayer(interaction);
|
const player = await resolvePlayer(interaction);
|
||||||
|
|
||||||
return await today(player);
|
return await today(player);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import usernameAutocomplete from '../core/autocomplete/username.js';
|
|||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||||
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
import negativeEmbed from '../core/interaction/negativeEmbed.js';
|
||||||
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
import positiveEmbed from '../core/interaction/positiveEmbed.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||||
import resolvePlayer from '../core/options/resolvePlayer.js';
|
import resolvePlayer from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
import { CommandRegistry } from '../events/interactionCreate/index.js';
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
import { PlayerClanData } from '../types/playerClanData.js';
|
import { PlayerClanData } from '../types/playerClanData.js';
|
||||||
@@ -22,7 +22,7 @@ export default {
|
|||||||
.setDescription("Set's the user's username to their in-game name")
|
.setDescription("Set's the user's username to their in-game name")
|
||||||
.addStringOption((option) => addUsernameOption(option).setRequired(true)),
|
.addStringOption((option) => addUsernameOption(option).setRequired(true)),
|
||||||
|
|
||||||
async execute(interaction) {
|
async handler(interaction) {
|
||||||
const blitzAccount = await resolvePlayer(interaction);
|
const blitzAccount = await resolvePlayer(interaction);
|
||||||
const { id, server } = blitzAccount;
|
const { id, server } = blitzAccount;
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import getWN8Percentile from '../core/blitz/getWN8Percentile.js';
|
import getWN8Percentile from '../core/blitz/getWN8Percentile.js';
|
||||||
import isNumber from '../core/process/isNumber.js';
|
import isNumber from '../core/node/isNumber.js';
|
||||||
import { AllStats, SupplementaryStats } from '../types/accountInfo.js';
|
import { AllStats, SupplementaryStats } from '../types/accountInfo.js';
|
||||||
import GenericStats from './GenericStats/index.js';
|
import GenericStats from './GenericStats/index.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import isDev from '../core/process/isDev.js';
|
import isDev from '../core/node/isDev.js';
|
||||||
import { theme } from '../stitches.config.js';
|
import { theme } from '../stitches.config.js';
|
||||||
|
|
||||||
export interface TitleBarProps {
|
export interface TitleBarProps {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { BlitzServer } from '../../constants/servers.js';
|
import { BlitzServer } from '../../constants/servers.js';
|
||||||
|
import errorWithCause from '../node/errorWithCause.js';
|
||||||
import { serverAndIdPattern } from '../options/resolvePlayer.js';
|
import { serverAndIdPattern } from '../options/resolvePlayer.js';
|
||||||
import errorWithCause from '../process/errorWithCause.js';
|
|
||||||
import listClansPanServer from './listClansPanServer.js';
|
import listClansPanServer from './listClansPanServer.js';
|
||||||
|
|
||||||
export default async function getBlitzClan(
|
export default async function getBlitzClan(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
|
||||||
import { TanksStats } from '../../types/tanksStats.js';
|
import { TanksStats } from '../../types/tanksStats.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||||
import errorWithCause from '../process/errorWithCause.js';
|
import errorWithCause from '../node/errorWithCause.js';
|
||||||
import getWargamingResponse from './getWargamingResponse.js';
|
import getWargamingResponse from './getWargamingResponse.js';
|
||||||
|
|
||||||
export default async function getTankStats(server: BlitzServer, id: number) {
|
export default async function getTankStats(server: BlitzServer, id: number) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
import { WargamingResponse } from '../../types/wargamingResponse.js';
|
||||||
import errorWithCause from '../process/errorWithCause.js';
|
import errorWithCause from '../node/errorWithCause.js';
|
||||||
|
|
||||||
export default async function getWargamingResponse<Data extends object>(
|
export default async function getWargamingResponse<Data extends object>(
|
||||||
url: string,
|
url: string,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlitzServer } from '../../constants/servers.js';
|
import { BlitzServer } from '../../constants/servers.js';
|
||||||
import { Account, AccountList } from '../../types/accountList.js';
|
import { Account, AccountList } from '../../types/accountList.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||||
import getWargamingResponse from './getWargamingResponse.js';
|
import getWargamingResponse from './getWargamingResponse.js';
|
||||||
|
|
||||||
export type AccountListWithServer = (Account & {
|
export type AccountListWithServer = (Account & {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlitzServer } from '../../constants/servers.js';
|
import { BlitzServer } from '../../constants/servers.js';
|
||||||
import { Clan, ClanList } from '../../types/clanList.js';
|
import { Clan, ClanList } from '../../types/clanList.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||||
import getWargamingResponse from './getWargamingResponse.js';
|
import getWargamingResponse from './getWargamingResponse.js';
|
||||||
|
|
||||||
export type ClanListWithServer = (Clan & {
|
export type ClanListWithServer = (Clan & {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { go } from 'fuzzysort';
|
import { go } from 'fuzzysort';
|
||||||
import errorWithCause from '../process/errorWithCause.js';
|
import errorWithCause from '../node/errorWithCause.js';
|
||||||
import { TANKS, tankopedia } from './tankopedia.js';
|
import { TANKS, tankopedia } from './tankopedia.js';
|
||||||
|
|
||||||
export default function resolveTankId(tank: string) {
|
export default function resolveTankId(tank: string) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
getHistoriesDefaultOptions,
|
getHistoriesDefaultOptions,
|
||||||
} from '../../types/histories.js';
|
} from '../../types/histories.js';
|
||||||
import getWargamingResponse from '../blitz/getWargamingResponse.js';
|
import getWargamingResponse from '../blitz/getWargamingResponse.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../process/args.js';
|
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
|
||||||
import { emptyAllStats } from './getTankStatsOverTime.js';
|
import { emptyAllStats } from './getTankStatsOverTime.js';
|
||||||
|
|
||||||
export interface PlayerHistoryRaw {
|
export interface PlayerHistoryRaw {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { ResponderReturnable } from '../../server.js';
|
||||||
|
import jsxToSvg from '../ui/jsxToSvg.js';
|
||||||
|
|
||||||
|
export default async function normalizeResponderReturnable(
|
||||||
|
returnable: ResponderReturnable,
|
||||||
|
) {
|
||||||
|
const awaitedReturnable = await returnable;
|
||||||
|
const svg = await jsxToSvg(awaitedReturnable);
|
||||||
|
|
||||||
|
return svg;
|
||||||
|
}
|
||||||
+17
-11
@@ -3,11 +3,12 @@ import {
|
|||||||
CacheType,
|
CacheType,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
import { Request } from 'express';
|
||||||
import { CYCLIC_API } from '../../constants/cyclic.js';
|
import { CYCLIC_API } from '../../constants/cyclic.js';
|
||||||
import getPeriodNow from '../blitzstars/getPeriodNow.js';
|
import getPeriodNow from '../blitzstars/getPeriodNow.js';
|
||||||
import getPeriodStart from '../blitzstars/getPeriodStart.js';
|
import getPeriodStart from '../blitzstars/getPeriodStart.js';
|
||||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
|
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo.js';
|
||||||
import { Period } from './addPeriodSubCommands.js';
|
import { Period } from '../options/addPeriodSubCommands.js';
|
||||||
|
|
||||||
export const PERIOD_NAMES: Record<Period, string> = {
|
export const PERIOD_NAMES: Record<Period, string> = {
|
||||||
today: "Today's statistics",
|
today: "Today's statistics",
|
||||||
@@ -34,10 +35,11 @@ export interface ResolvedPeriod {
|
|||||||
end: number;
|
end: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function resolvePeriod(
|
export default function resolvePeriodFromCommand(
|
||||||
interaction:
|
input:
|
||||||
| ChatInputCommandInteraction<CacheType>
|
| ChatInputCommandInteraction<CacheType>
|
||||||
| ButtonInteraction<CacheType>,
|
| ButtonInteraction<CacheType>
|
||||||
|
| Request,
|
||||||
) {
|
) {
|
||||||
let statsName: string;
|
let statsName: string;
|
||||||
let evolutionName: string;
|
let evolutionName: string;
|
||||||
@@ -46,22 +48,26 @@ export default function resolvePeriod(
|
|||||||
let url: URL;
|
let url: URL;
|
||||||
let period: Period;
|
let period: Period;
|
||||||
|
|
||||||
if (interaction instanceof ChatInputCommandInteraction) {
|
if (input instanceof ChatInputCommandInteraction) {
|
||||||
period = interaction.options.getSubcommand() as Period;
|
period = input.options.getSubcommand() as Period;
|
||||||
} else {
|
} else {
|
||||||
url = new URL(`${CYCLIC_API}/${interaction.customId}`);
|
url = new URL(
|
||||||
|
`${CYCLIC_API}${
|
||||||
|
input instanceof ButtonInteraction ? `/${input.customId}` : input.path
|
||||||
|
}`,
|
||||||
|
);
|
||||||
const path = url.pathname.split('/').filter(Boolean);
|
const path = url.pathname.split('/').filter(Boolean);
|
||||||
period = path[path.length - 1] as Period;
|
period = path[path.length - 1] as Period;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (period === 'custom') {
|
if (period === 'custom') {
|
||||||
const startRaw =
|
const startRaw =
|
||||||
interaction instanceof ChatInputCommandInteraction
|
input instanceof ChatInputCommandInteraction
|
||||||
? interaction.options.getInteger('start')!
|
? input.options.getInteger('start')!
|
||||||
: parseInt(url!.searchParams.get('start')!);
|
: parseInt(url!.searchParams.get('start')!);
|
||||||
const endRaw =
|
const endRaw =
|
||||||
interaction instanceof ChatInputCommandInteraction
|
input instanceof ChatInputCommandInteraction
|
||||||
? interaction.options.getInteger('end')!
|
? input.options.getInteger('end')!
|
||||||
: parseInt(url!.searchParams.get('end')!);
|
: parseInt(url!.searchParams.get('end')!);
|
||||||
const startMin = Math.min(startRaw, endRaw);
|
const startMin = Math.min(startRaw, endRaw);
|
||||||
const endMax = Math.max(startRaw, endRaw);
|
const endMax = Math.max(startRaw, endRaw);
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -2,7 +2,7 @@ import {
|
|||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
SlashCommandSubcommandGroupBuilder,
|
SlashCommandSubcommandGroupBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { PERIOD_NAMES } from './resolvePeriod.js';
|
import { PERIOD_NAMES } from '../interaction/resolvePeriodFromCommand.js';
|
||||||
|
|
||||||
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
export type Period = 'today' | '30' | '60' | '90' | 'career' | 'custom';
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { BlitzServer } from '../../constants/servers.js';
|
|||||||
import listAccountsPanServer, {
|
import listAccountsPanServer, {
|
||||||
usernamePatternWithoutPosition,
|
usernamePatternWithoutPosition,
|
||||||
} from '../blitz/listAccountsPanServer.js';
|
} from '../blitz/listAccountsPanServer.js';
|
||||||
import errorWithCause from '../process/errorWithCause.js';
|
import errorWithCause from '../node/errorWithCause.js';
|
||||||
|
|
||||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import { EmbedBuilder, TextChannel } from 'discord.js';
|
|||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
import { client } from '../bot.js';
|
import { client } from '../bot.js';
|
||||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||||
import isDev from '../core/process/isDev.js';
|
import isDev from '../core/node/isDev.js';
|
||||||
|
|
||||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||||
const CLIENT_ERROR_EVENTS = ['error'];
|
const CLIENT_ERROR_EVENTS = ['error'];
|
||||||
|
|||||||
@@ -8,24 +8,24 @@ import {
|
|||||||
import negativeEmbed from '../../../core/interaction/negativeEmbed.js';
|
import negativeEmbed from '../../../core/interaction/negativeEmbed.js';
|
||||||
import normalizeInteractionReturnable from '../../../core/interaction/normalizeInteractionReturnable.js';
|
import normalizeInteractionReturnable from '../../../core/interaction/normalizeInteractionReturnable.js';
|
||||||
import warningEmbed from '../../../core/interaction/warningEmbed.js';
|
import warningEmbed from '../../../core/interaction/warningEmbed.js';
|
||||||
import { psa } from '../../../core/process/psa.js';
|
import { psa } from '../../../core/node/psa.js';
|
||||||
import { handleError } from '../../error.js';
|
import { handleError } from '../../error.js';
|
||||||
import { commands } from '../index.js';
|
import { commands } from '../index.js';
|
||||||
|
|
||||||
export default async function handleChatInputCommand(
|
export default async function handleChatInputCommand(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
) {
|
) {
|
||||||
const command = commands[interaction.commandName];
|
const registry = commands[interaction.commandName];
|
||||||
|
|
||||||
console.log(interaction.toString());
|
console.log(interaction.toString());
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const returnable = await command.execute(interaction);
|
const returnable = await registry.handler(interaction);
|
||||||
|
|
||||||
if (command.handlesInteraction) return;
|
if (registry.handlesInteraction) return;
|
||||||
|
|
||||||
const reply = await normalizeInteractionReturnable(returnable!);
|
const reply = await normalizeInteractionReturnable(returnable);
|
||||||
|
|
||||||
if (psa.data) {
|
if (psa.data) {
|
||||||
if (!reply.embeds) reply.embeds = [];
|
if (!reply.embeds) reply.embeds = [];
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ import searchtanks from '../../commands/searchtanks.js';
|
|||||||
import stats from '../../commands/stats.js';
|
import stats from '../../commands/stats.js';
|
||||||
import today from '../../commands/today.js';
|
import today from '../../commands/today.js';
|
||||||
import verify from '../../commands/verify.js';
|
import verify from '../../commands/verify.js';
|
||||||
import { DISCORD_TOKEN } from '../../core/process/args.js';
|
import { DISCORD_TOKEN } from '../../core/node/args.js';
|
||||||
import getClientId from '../../core/process/getClientId.js';
|
import getClientId from '../../core/node/getClientId.js';
|
||||||
import isDev from '../../core/process/isDev.js';
|
import isDev from '../../core/node/isDev.js';
|
||||||
import handleAutocomplete from './handlers/autocomplete.js';
|
import handleAutocomplete from './handlers/autocomplete.js';
|
||||||
import handleButton from './handlers/button.js';
|
import handleButton from './handlers/button.js';
|
||||||
import handleChatInputCommand from './handlers/chatInputCommand.js';
|
import handleChatInputCommand from './handlers/chatInputCommand.js';
|
||||||
@@ -46,29 +46,26 @@ export type InteractionReturnable =
|
|||||||
| InteractionIterableReturnable
|
| InteractionIterableReturnable
|
||||||
| Promise<InteractionIterableReturnable>;
|
| Promise<InteractionIterableReturnable>;
|
||||||
|
|
||||||
export type CommandRegistry = {
|
export interface Registry {
|
||||||
inDevelopment: boolean;
|
inDevelopment: boolean;
|
||||||
inProduction: boolean;
|
inProduction: boolean;
|
||||||
inPublic: boolean;
|
}
|
||||||
|
|
||||||
|
export interface CommandRegistry<HandlesInteraction extends boolean = false>
|
||||||
|
extends Registry {
|
||||||
|
inPublic: boolean;
|
||||||
|
handlesInteraction?: HandlesInteraction;
|
||||||
command:
|
command:
|
||||||
| SlashCommandBuilder
|
| SlashCommandBuilder
|
||||||
| SlashCommandSubcommandsOnlyBuilder
|
| SlashCommandSubcommandsOnlyBuilder
|
||||||
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||||
|
|
||||||
|
handler: (
|
||||||
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
|
) => HandlesInteraction extends true ? void : InteractionReturnable;
|
||||||
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
|
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
|
||||||
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
|
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
|
||||||
} & (
|
}
|
||||||
| {
|
|
||||||
handlesInteraction?: false;
|
|
||||||
execute: (
|
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
|
||||||
) => InteractionReturnable;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
handlesInteraction: true;
|
|
||||||
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const rest = new REST().setToken(DISCORD_TOKEN);
|
const rest = new REST().setToken(DISCORD_TOKEN);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { Client } from 'discord.js';
|
import { Client } from 'discord.js';
|
||||||
import isDev from '../core/process/isDev.js';
|
import isDev from '../core/node/isDev.js';
|
||||||
|
|
||||||
export default function ready(client: Client<true>) {
|
export default function ready(client: Client<true>) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import resolveTankName from '../core/blitz/resolveTankName.js';
|
|||||||
import { tankopedia } from '../core/blitz/tankopedia.js';
|
import { tankopedia } from '../core/blitz/tankopedia.js';
|
||||||
import getPlayerHistories from '../core/blitzstars/getPlayerHistories.js';
|
import getPlayerHistories from '../core/blitzstars/getPlayerHistories.js';
|
||||||
import getTankHistories from '../core/blitzstars/getTankHistories.js';
|
import getTankHistories from '../core/blitzstars/getTankHistories.js';
|
||||||
import { ResolvedPeriod } from '../core/options/resolvePeriod.js';
|
import { ResolvedPeriod } from '../core/interaction/resolvePeriodFromCommand.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { AccountInfo } from '../types/accountInfo.js';
|
import { AccountInfo } from '../types/accountInfo.js';
|
||||||
import { Histories } from '../types/histories.js';
|
import { Histories } from '../types/histories.js';
|
||||||
import { PlayerClanData } from '../types/playerClanData.js';
|
import { PlayerClanData } from '../types/playerClanData.js';
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import sumStats from '../core/blitz/sumStats.js';
|
|||||||
import { Tier, tankopedia } from '../core/blitz/tankopedia.js';
|
import { Tier, tankopedia } from '../core/blitz/tankopedia.js';
|
||||||
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||||
import { ResolvedPeriod } from '../core/options/resolvePeriod.js';
|
import { ResolvedPeriod } from '../core/interaction/resolvePeriodFromCommand.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import {
|
import {
|
||||||
AccountInfo,
|
AccountInfo,
|
||||||
AllStats,
|
AllStats,
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
|
|||||||
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
import getTankStatsOverTime from '../core/blitzstars/getTankStatsOverTime.js';
|
||||||
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo.js';
|
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo.js';
|
||||||
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
import { tankAverages } from '../core/blitzstars/tankAverages.js';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
|
||||||
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
import { ResolvedPlayer } from '../core/options/resolvePlayer.js';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../core/process/args.js';
|
|
||||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||||
import { PlayerClanData } from '../types/playerClanData.js';
|
import { PlayerClanData } from '../types/playerClanData.js';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { BlitzServer } from '../constants/servers.js';
|
||||||
|
import resolvePeriodFromCommand from '../core/interaction/resolvePeriodFromCommand.js';
|
||||||
|
import stats, { StatType } from '../renderers/stats.js';
|
||||||
|
import { ResponderRegistry } from '../server.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
route: '/stats/:type/:period',
|
||||||
|
inProduction: true,
|
||||||
|
inDevelopment: true,
|
||||||
|
|
||||||
|
async handler(req) {
|
||||||
|
console.log('yeah');
|
||||||
|
|
||||||
|
return await stats(
|
||||||
|
req.params.type as StatType,
|
||||||
|
resolvePeriodFromCommand(req),
|
||||||
|
{
|
||||||
|
server: req.query.server as BlitzServer,
|
||||||
|
id: parseInt(req.query.id as string),
|
||||||
|
},
|
||||||
|
parseInt(req.query.tank as string),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
} satisfies ResponderRegistry;
|
||||||
+32
-10
@@ -1,18 +1,40 @@
|
|||||||
import express from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import jsxToSvg from './core/ui/jsxToSvg.js';
|
import normalizeResponderReturnable from './core/express/normalizeResponderReturnable.js';
|
||||||
import today from './renderers/today.js';
|
import isDev from './core/node/isDev.js';
|
||||||
|
import { Registry } from './events/interactionCreate/index.js';
|
||||||
|
import stats from './responders/stats.js';
|
||||||
|
|
||||||
|
export type ResponderReturnable = JSX.Element | Promise<JSX.Element>;
|
||||||
|
|
||||||
|
export interface ResponderRegistry<HandlesInteraction extends boolean = false>
|
||||||
|
extends Registry {
|
||||||
|
route: string;
|
||||||
|
handlesInteraction?: HandlesInteraction;
|
||||||
|
|
||||||
|
handler: (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
) => HandlesInteraction extends true ? void : ResponderReturnable;
|
||||||
|
}
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.get('/', async (req, res) => {
|
([stats] as ResponderRegistry[]).forEach((registry) => {
|
||||||
const jsx = await today({ server: 'com', id: 1028700193 });
|
if (!(isDev() ? registry.inDevelopment : registry.inProduction)) return;
|
||||||
const svg = await jsxToSvg(jsx);
|
|
||||||
|
|
||||||
res.writeHead(200, {
|
app.get(registry.route, async (req, res) => {
|
||||||
'Content-Type': 'image/svg+xml',
|
const returnable = registry.handler(req, res);
|
||||||
'Content-Length': svg.length,
|
|
||||||
|
if (registry.handlesInteraction) return;
|
||||||
|
|
||||||
|
const response = await normalizeResponderReturnable(returnable);
|
||||||
|
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'image/svg+xml',
|
||||||
|
'Content-Length': response.length,
|
||||||
|
});
|
||||||
|
res.end(response);
|
||||||
});
|
});
|
||||||
res.end(svg);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(process.env.PORT ?? 3000);
|
app.listen(process.env.PORT ?? 3000);
|
||||||
+1
-1
@@ -11,5 +11,5 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"jsx": "react-jsx"
|
"jsx": "react-jsx"
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/renderers/stats.tsx", "src/events/interactionCreate/handlers/button.tsx"]
|
"include": ["src/**/*.ts", "src/renderers/stats.tsx", "src/events/interactionCreate/handlers/button.tsx", "src/responders/stats.tsx"]
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user