mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: code split a lot
This commit is contained in:
1 parent
78e4c82f20
commit
d2668974f7
18 files changed
+155
-133
No files matched your search
@@ -12,7 +12,7 @@ import embedNegative from '../core/discord/embedNegative';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { theme } from '../stitches.config';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { PlayerClanInfo } from '../types/playerClanData';
|
||||
|
||||
const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
|
||||
@@ -99,7 +99,7 @@ export const verifyCommand: CommandRegistry = {
|
||||
getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
),
|
||||
getWargamingResponse<PlayerClanData>(
|
||||
getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -21,7 +21,7 @@ import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { PlayerClanInfo } from '../types/playerClanData';
|
||||
|
||||
const COMP_TANKS = [
|
||||
// light tanks
|
||||
@@ -70,7 +70,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
||||
})),
|
||||
)
|
||||
).filter((tank) => tank.tankopedia?.tier === tier);
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
const clanData = await getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
||||
|
||||
@@ -26,7 +26,7 @@ import { octokit } from '../core/github/octokit';
|
||||
import throwError from '../core/node/throwError';
|
||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
import { PlayerClanInfo } from '../types/playerClanData';
|
||||
|
||||
export interface RatingsPlayer {
|
||||
spa_id: number;
|
||||
@@ -313,7 +313,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||
lastPlayerIndex + 1,
|
||||
);
|
||||
const ids = trimmed.map((player) => player.id).join(',');
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
const clanData = await getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
||||
);
|
||||
|
||||
@@ -377,7 +377,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const clan = (
|
||||
await getWargamingResponse<PlayerClanData>(
|
||||
await getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
)
|
||||
)[id]?.clan;
|
||||
@@ -437,7 +437,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||
playerIndex + halfRange + 1,
|
||||
);
|
||||
const ids = trimmed.map((player) => player.id).join(',');
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
const clanData = await getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${ids}&extra=clan`,
|
||||
);
|
||||
|
||||
|
||||
+19
-53
@@ -1,20 +1,22 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import AllStatsOverview from '../components/AllStatsOverview';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import { TreeTypeString } from '../components/Tanks';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||
import { StatFilters, filterStats } from '../core/blitz/filterStats';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||
import { getClanLogo } from '../core/blitz/getClanLogo';
|
||||
import { playerClanInfo } from '../core/blitz/playerClanInfo';
|
||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
||||
import { PeriodType } from '../core/discord/addPeriodSubCommands';
|
||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||
import { getFiltersFromCommand } from '../core/discord/getFiltersFromCommand';
|
||||
import interactionToURL from '../core/discord/interactionToURL';
|
||||
import { refreshButton } from '../core/discord/refreshButton';
|
||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||
@@ -26,27 +28,15 @@ import resolvePlayerFromCommand, {
|
||||
ResolvedPlayer,
|
||||
} from '../core/discord/resolvePlayerFromCommand';
|
||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { PlayerClanData } from '../types/playerClanData';
|
||||
|
||||
export default async function render(
|
||||
{ region, id }: ResolvedPlayer,
|
||||
{ start, end, name: statsName }: ResolvedPeriod,
|
||||
{ start, end, name }: ResolvedPeriod,
|
||||
filters: StatFilters,
|
||||
) {
|
||||
const nickname = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
)[id].nickname;
|
||||
const clan = (
|
||||
await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
)
|
||||
)[id]?.clan;
|
||||
const clanImage = clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clan.emblem_set_id}.png`
|
||||
: undefined;
|
||||
const nickname = (await getAccountInfo(region, id))[id].nickname;
|
||||
const clan = (await playerClanInfo(region, id))[id]?.clan;
|
||||
const clanImage = clan ? getClanLogo(clan.emblem_set_id) : undefined;
|
||||
const diffedTankStats = await getDiffedTankStats(region, id, start, end);
|
||||
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||
|
||||
@@ -55,7 +45,7 @@ export default async function render(
|
||||
<TitleBar
|
||||
name={nickname}
|
||||
image={clanImage}
|
||||
description={`${statsName} • ${await filtersToDescription(filters)}`}
|
||||
description={`${name} • ${await filtersToDescription(filters)}`}
|
||||
/>
|
||||
|
||||
{!stats?.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||
@@ -86,34 +76,18 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
||||
resolvedPlayer.region,
|
||||
interaction,
|
||||
);
|
||||
const filters = {
|
||||
nation: interaction.options.getString('nation') ?? undefined,
|
||||
tier:
|
||||
parseInt(interaction.options.getString('tier') ?? '0') || undefined,
|
||||
tankType: interaction.options.getString('tank-type') ?? undefined,
|
||||
treeType:
|
||||
(interaction.options.getString('tree-type') as
|
||||
| TreeTypeString
|
||||
| undefined) ?? undefined,
|
||||
tank:
|
||||
parseInt(interaction.options.getString('tank') ?? '0') || undefined,
|
||||
} satisfies StatFilters;
|
||||
const filters = getFiltersFromCommand(interaction);
|
||||
const path = interactionToURL(interaction, {
|
||||
...resolvedPlayer,
|
||||
...((interaction.options.getSubcommand() as PeriodType) === 'custom'
|
||||
? {
|
||||
start: interaction.options.getInteger('start', true),
|
||||
end: interaction.options.getInteger('end', true),
|
||||
}
|
||||
: undefined),
|
||||
...getCustomPeriodParams(interaction),
|
||||
...filters,
|
||||
});
|
||||
|
||||
return [
|
||||
await render(resolvedPlayer, resolvedPeriod, filters),
|
||||
return Promise.all([
|
||||
render(resolvedPlayer, resolvedPeriod, filters),
|
||||
refreshButton(interaction, path),
|
||||
await getBlitzStarsLinkButton(resolvedPlayer.region, resolvedPlayer.id),
|
||||
];
|
||||
getBlitzStarsLinkButton(resolvedPlayer.region, resolvedPlayer.id),
|
||||
]);
|
||||
},
|
||||
|
||||
autocomplete: (interaction) => {
|
||||
@@ -122,19 +96,11 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
||||
},
|
||||
|
||||
async button(interaction) {
|
||||
const url = new URL(`https://example.com${interaction.customId}`);
|
||||
const player = await resolvePlayerFromButton(interaction);
|
||||
const period = resolvePeriodFromButton(player.region, interaction);
|
||||
const filters = getFiltersFromButton(interaction);
|
||||
|
||||
return await render(player, period, {
|
||||
nation: url.searchParams.get('nation') ?? undefined,
|
||||
tank: parseInt(url.searchParams.get('tank') ?? '0') || undefined,
|
||||
tankType: url.searchParams.get('tank-type') ?? undefined,
|
||||
treeType:
|
||||
(url.searchParams.get('tree-type') as TreeTypeString | undefined) ??
|
||||
undefined,
|
||||
tier: parseInt(url.searchParams.get('tier') ?? '0') || undefined,
|
||||
});
|
||||
return await render(player, period, filters);
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user