mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 19:49:50 +01: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 { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { theme } from '../stitches.config';
|
import { theme } from '../stitches.config';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
import { AccountInfo } from '../types/accountInfo';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
|
|
||||||
const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ export const verifyCommand: CommandRegistry = {
|
|||||||
getWargamingResponse<AccountInfo>(
|
getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
`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`,
|
`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 resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistry } from '../events/interactionCreate';
|
import { CommandRegistry } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
import { AccountInfo } from '../types/accountInfo';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
|
|
||||||
const COMP_TANKS = [
|
const COMP_TANKS = [
|
||||||
// light tanks
|
// light tanks
|
||||||
@@ -70,7 +70,7 @@ export const ownedTanksCommand: CommandRegistry = {
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
).filter((tank) => tank.tankopedia?.tier === tier);
|
).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`,
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
);
|
);
|
||||||
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
const groupedTanks: Record<string, TankopediaEntry[]> = {};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import { octokit } from '../core/github/octokit';
|
|||||||
import throwError from '../core/node/throwError';
|
import throwError from '../core/node/throwError';
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
import { AccountInfo } from '../types/accountInfo';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
|
|
||||||
export interface RatingsPlayer {
|
export interface RatingsPlayer {
|
||||||
spa_id: number;
|
spa_id: number;
|
||||||
@@ -313,7 +313,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
lastPlayerIndex + 1,
|
lastPlayerIndex + 1,
|
||||||
);
|
);
|
||||||
const ids = trimmed.map((player) => player.id).join(',');
|
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`,
|
`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}`,
|
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
const clan = (
|
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`,
|
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
)
|
)
|
||||||
)[id]?.clan;
|
)[id]?.clan;
|
||||||
@@ -437,7 +437,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
playerIndex + halfRange + 1,
|
playerIndex + halfRange + 1,
|
||||||
);
|
);
|
||||||
const ids = trimmed.map((player) => player.id).join(',');
|
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`,
|
`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 { SlashCommandBuilder } from 'discord.js';
|
||||||
import AllStatsOverview from '../components/AllStatsOverview';
|
import AllStatsOverview from '../components/AllStatsOverview';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
import { TreeTypeString } from '../components/Tanks';
|
|
||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
import Wrapper from '../components/Wrapper';
|
||||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
|
||||||
import { StatFilters, filterStats } from '../core/blitz/filterStats';
|
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 { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||||
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
||||||
import { PeriodType } from '../core/discord/addPeriodSubCommands';
|
|
||||||
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups';
|
||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
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 interactionToURL from '../core/discord/interactionToURL';
|
||||||
import { refreshButton } from '../core/discord/refreshButton';
|
import { refreshButton } from '../core/discord/refreshButton';
|
||||||
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton';
|
||||||
@@ -26,27 +28,15 @@ import resolvePlayerFromCommand, {
|
|||||||
ResolvedPlayer,
|
ResolvedPlayer,
|
||||||
} from '../core/discord/resolvePlayerFromCommand';
|
} from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
|
||||||
|
|
||||||
export default async function render(
|
export default async function render(
|
||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name: statsName }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
) {
|
) {
|
||||||
const nickname = (
|
const nickname = (await getAccountInfo(region, id))[id].nickname;
|
||||||
await getWargamingResponse<AccountInfo>(
|
const clan = (await playerClanInfo(region, id))[id]?.clan;
|
||||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
const clanImage = clan ? getClanLogo(clan.emblem_set_id) : undefined;
|
||||||
)
|
|
||||||
)[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 diffedTankStats = await getDiffedTankStats(region, id, start, end);
|
const diffedTankStats = await getDiffedTankStats(region, id, start, end);
|
||||||
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||||
|
|
||||||
@@ -55,7 +45,7 @@ export default async function render(
|
|||||||
<TitleBar
|
<TitleBar
|
||||||
name={nickname}
|
name={nickname}
|
||||||
image={clanImage}
|
image={clanImage}
|
||||||
description={`${statsName} • ${await filtersToDescription(filters)}`}
|
description={`${name} • ${await filtersToDescription(filters)}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!stats?.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
{!stats?.battles && <NoData type={NoDataType.BattlesInPeriod} />}
|
||||||
@@ -86,34 +76,18 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
resolvedPlayer.region,
|
resolvedPlayer.region,
|
||||||
interaction,
|
interaction,
|
||||||
);
|
);
|
||||||
const filters = {
|
const filters = getFiltersFromCommand(interaction);
|
||||||
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 path = interactionToURL(interaction, {
|
const path = interactionToURL(interaction, {
|
||||||
...resolvedPlayer,
|
...resolvedPlayer,
|
||||||
...((interaction.options.getSubcommand() as PeriodType) === 'custom'
|
...getCustomPeriodParams(interaction),
|
||||||
? {
|
|
||||||
start: interaction.options.getInteger('start', true),
|
|
||||||
end: interaction.options.getInteger('end', true),
|
|
||||||
}
|
|
||||||
: undefined),
|
|
||||||
...filters,
|
...filters,
|
||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return Promise.all([
|
||||||
await render(resolvedPlayer, resolvedPeriod, filters),
|
render(resolvedPlayer, resolvedPeriod, filters),
|
||||||
refreshButton(interaction, path),
|
refreshButton(interaction, path),
|
||||||
await getBlitzStarsLinkButton(resolvedPlayer.region, resolvedPlayer.id),
|
getBlitzStarsLinkButton(resolvedPlayer.region, resolvedPlayer.id),
|
||||||
];
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
autocomplete: (interaction) => {
|
autocomplete: (interaction) => {
|
||||||
@@ -122,19 +96,11 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async button(interaction) {
|
async button(interaction) {
|
||||||
const url = new URL(`https://example.com${interaction.customId}`);
|
|
||||||
const player = await resolvePlayerFromButton(interaction);
|
const player = await resolvePlayerFromButton(interaction);
|
||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await render(player, period, {
|
return await render(player, period, filters);
|
||||||
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,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { Region } from '../../constants/regions';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||||
|
import { AccountInfo } from '../../types/accountInfo';
|
||||||
|
import getWargamingResponse from './getWargamingResponse';
|
||||||
|
|
||||||
|
// BIG TODO: generalize all get wargaming calls
|
||||||
|
export function getAccountInfo(region: Region, id: number) {
|
||||||
|
return getWargamingResponse<AccountInfo>(
|
||||||
|
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export function getClanLogo(emblemId: number) {
|
||||||
|
return `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${emblemId}.png`
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Region } from '../../constants/regions';
|
||||||
|
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||||
|
import { PlayerClanInfo } from '../../types/playerClanData';
|
||||||
|
import getWargamingResponse from './getWargamingResponse';
|
||||||
|
|
||||||
|
export function playerClanInfo(region: Region, id: number) {
|
||||||
|
return getWargamingResponse<PlayerClanInfo>(
|
||||||
|
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { ChatInputCommandInteraction } from 'discord.js';
|
||||||
|
import { PeriodType } from './addPeriodSubCommands';
|
||||||
|
|
||||||
|
export function getCustomPeriodParams(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
) {
|
||||||
|
if ((interaction.options.getSubcommand() as PeriodType) === 'custom')
|
||||||
|
return {
|
||||||
|
start: interaction.options.getInteger('start', true),
|
||||||
|
end: interaction.options.getInteger('end', true),
|
||||||
|
};
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { ButtonInteraction } from 'discord.js';
|
||||||
|
import { TreeTypeString } from '../../components/Tanks';
|
||||||
|
import { StatFilters } from '../blitz/filterStats';
|
||||||
|
|
||||||
|
export function getFiltersFromButton(interaction: ButtonInteraction) {
|
||||||
|
const url = new URL(`https://example.com/${interaction.customId}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
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,
|
||||||
|
} satisfies StatFilters;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { ChatInputCommandInteraction } from 'discord.js';
|
||||||
|
import { TreeTypeString } from '../../components/Tanks';
|
||||||
|
import { StatFilters } from '../blitz/filterStats';
|
||||||
|
|
||||||
|
export function getFiltersFromCommand(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,13 +1,43 @@
|
|||||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
import { ButtonInteraction } from 'discord.js';
|
||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||||
|
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||||
|
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||||
|
import { PeriodType } from './addPeriodSubCommands';
|
||||||
|
import {
|
||||||
|
ResolvedPeriod,
|
||||||
|
getPeriodOptionName,
|
||||||
|
} from './resolvePeriodFromCommand';
|
||||||
|
|
||||||
export default function resolvePeriodFromButton(
|
export default function resolvePeriodFromButton(
|
||||||
server: Region,
|
region: Region,
|
||||||
interaction: ButtonInteraction<CacheType>,
|
interaction: ButtonInteraction,
|
||||||
) {
|
) {
|
||||||
return resolvePeriodFromURL(
|
let name: string;
|
||||||
server,
|
let start: number;
|
||||||
`https://example.com/${interaction.customId}`,
|
let end: number;
|
||||||
);
|
const url = new URL(`https://example.com/${interaction.customId}`);
|
||||||
|
const path = url.pathname.split('/');
|
||||||
|
const periodSubcommand = path[2] as PeriodType;
|
||||||
|
|
||||||
|
if (periodSubcommand === 'custom') {
|
||||||
|
const startRaw = parseInt(url!.searchParams.get('start')!);
|
||||||
|
const endRaw = parseInt(url!.searchParams.get('end')!);
|
||||||
|
const startDaysAgoMin = Math.min(startRaw, endRaw);
|
||||||
|
const endDaysAgoMax = Math.max(startRaw, endRaw);
|
||||||
|
|
||||||
|
name = `${startDaysAgoMin} - ${endDaysAgoMax} days`;
|
||||||
|
start = getTimeDaysAgo(region, endDaysAgoMax);
|
||||||
|
end = getTimeDaysAgo(region, startDaysAgoMin);
|
||||||
|
} else {
|
||||||
|
name = getPeriodOptionName(periodSubcommand);
|
||||||
|
start = getPeriodStart(region, periodSubcommand);
|
||||||
|
end = getPeriodNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
} satisfies ResolvedPeriod;
|
||||||
}
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { Region } from '../../constants/regions';
|
|
||||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
|
||||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
|
||||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
|
||||||
import { PeriodType } from './addPeriodSubCommands';
|
|
||||||
import {
|
|
||||||
ResolvedPeriod,
|
|
||||||
getPeriodOptionName,
|
|
||||||
} from './resolvePeriodFromCommand';
|
|
||||||
|
|
||||||
export default function resolvePeriodFromURL(
|
|
||||||
region: Region,
|
|
||||||
urlString: string,
|
|
||||||
) {
|
|
||||||
let name: string;
|
|
||||||
let start: number;
|
|
||||||
let end: number;
|
|
||||||
const url = new URL(urlString);
|
|
||||||
const path = url.pathname.split('/');
|
|
||||||
const periodSubcommand = path[2] as PeriodType;
|
|
||||||
|
|
||||||
if (periodSubcommand === 'custom') {
|
|
||||||
const startRaw = parseInt(url!.searchParams.get('start')!);
|
|
||||||
const endRaw = parseInt(url!.searchParams.get('end')!);
|
|
||||||
const startDaysAgoMin = Math.min(startRaw, endRaw);
|
|
||||||
const endDaysAgoMax = Math.max(startRaw, endRaw);
|
|
||||||
|
|
||||||
name = `${startDaysAgoMin} - ${endDaysAgoMax} days`;
|
|
||||||
start = getTimeDaysAgo(region, endDaysAgoMax);
|
|
||||||
end = getTimeDaysAgo(region, startDaysAgoMin);
|
|
||||||
} else {
|
|
||||||
name = getPeriodOptionName(periodSubcommand);
|
|
||||||
start = getPeriodStart(region, periodSubcommand);
|
|
||||||
end = getPeriodNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
} satisfies ResolvedPeriod;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
import { ButtonInteraction } from 'discord.js';
|
||||||
import resolvePlayerFromURL from './resolvePlayerFromURL';
|
import { Region } from '../../constants/regions';
|
||||||
|
import { ResolvedPlayer } from './resolvePlayerFromCommand';
|
||||||
|
|
||||||
export default async function resolvePlayerFromButton(
|
export default async function resolvePlayerFromButton(
|
||||||
interaction: ButtonInteraction<CacheType>,
|
interaction: ButtonInteraction,
|
||||||
) {
|
) {
|
||||||
return resolvePlayerFromURL(`https://exmaple.com/${interaction.customId}`);
|
const url = new URL(`https://exmaple.com/${interaction.customId}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: parseInt(url.searchParams.get('id')!),
|
||||||
|
region: url.searchParams.get('region') as Region,
|
||||||
|
} satisfies ResolvedPlayer;
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { Region } from '../../constants/regions';
|
|
||||||
import { ResolvedPlayer } from '../discord/resolvePlayerFromCommand';
|
|
||||||
|
|
||||||
export default function resolvePlayerFromURL(urlString: string) {
|
|
||||||
const url = new URL(urlString);
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: parseInt(url.searchParams.get('id')!),
|
|
||||||
region: url.searchParams.get('region') as Region,
|
|
||||||
} satisfies ResolvedPlayer;
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand';
|
|||||||
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand';
|
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { AccountInfo } from '../types/accountInfo';
|
import { AccountInfo } from '../types/accountInfo';
|
||||||
import { Histories } from '../types/histories';
|
import { Histories } from '../types/histories';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
import { StatType } from './stats';
|
import { StatType } from './stats';
|
||||||
|
|
||||||
export default async function evolution<Type extends StatType>(
|
export default async function evolution<Type extends StatType>(
|
||||||
@@ -26,7 +26,7 @@ export default async function evolution<Type extends StatType>(
|
|||||||
|
|
||||||
if (type === 'player') {
|
if (type === 'player') {
|
||||||
const clan = (
|
const clan = (
|
||||||
await getWargamingResponse<PlayerClanData>(
|
await getWargamingResponse<PlayerClanInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
)
|
)
|
||||||
)[id]?.clan;
|
)[id]?.clan;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
AllStats,
|
AllStats,
|
||||||
SupplementaryStats,
|
SupplementaryStats,
|
||||||
} from '../types/accountInfo';
|
} from '../types/accountInfo';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
import { MultiTankFilters, StatType } from './stats';
|
import { MultiTankFilters, StatType } from './stats';
|
||||||
|
|
||||||
export default async function fullStats<Type extends StatType>(
|
export default async function fullStats<Type extends StatType>(
|
||||||
@@ -36,7 +36,7 @@ export default async function fullStats<Type extends StatType>(
|
|||||||
|
|
||||||
if (type === 'player' || type === 'multi-tank') {
|
if (type === 'player' || type === 'multi-tank') {
|
||||||
const clan = (
|
const clan = (
|
||||||
await getWargamingResponse<PlayerClanData>(
|
await getWargamingResponse<PlayerClanInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
)
|
)
|
||||||
)[id]?.clan;
|
)[id]?.clan;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
|||||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||||
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand';
|
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand';
|
||||||
import { AccountInfo, AllStats } from '../types/accountInfo';
|
import { AccountInfo, AllStats } from '../types/accountInfo';
|
||||||
import { PlayerClanData } from '../types/playerClanData';
|
import { PlayerClanInfo } from '../types/playerClanData';
|
||||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||||
|
|
||||||
export default async function today(
|
export default async function today(
|
||||||
@@ -36,7 +36,7 @@ export default async function today(
|
|||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
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`,
|
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||||
);
|
);
|
||||||
const careerTankStatsRaw = await getTankStats(server, id);
|
const careerTankStatsRaw = await getTankStats(server, id);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export type PlayerClanData = {
|
export type PlayerClanInfo = {
|
||||||
[accountId: number]: {
|
[accountId: number]: {
|
||||||
account_id: number;
|
account_id: number;
|
||||||
joined_at: number;
|
joined_at: number;
|
||||||
|
|||||||
Reference in new issue
Block a user