mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: core chunk 2
This commit is contained in:
1 parent
e96538bae0
commit
862445259e
17 files changed
+33
-71
No files matched your search
@@ -3,12 +3,12 @@ import {
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo';
|
||||
import * as Graph from '../components/Graph';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { getClanLogo } from '../core/blitz/getClanLogo';
|
||||
import { getPlayerClanInfo } from '../core/blitz/getPlayerClanInfo';
|
||||
import resolveTankId from '../core/blitz/resolveTankId';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import getPlayerHistories from '../core/blitzstars/getPlayerHistories';
|
||||
@@ -40,7 +40,7 @@ async function render(
|
||||
tankId: number | null,
|
||||
) {
|
||||
const accountInfo = await getAccountInfo(region, id);
|
||||
const clan = (await getPlayerClanInfo(region, id))[id]?.clan;
|
||||
const clan = (await getClanAccountInfo(region, id))?.clan;
|
||||
const logo = clan ? getClanLogo(clan.emblem_set_id) : undefined;
|
||||
const histories = await (type === 'player'
|
||||
? getPlayerHistories(region, id, {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo';
|
||||
import { StatFilters, filterStats } from '../_core/statistics/filterStats';
|
||||
import GenericAllStats from '../components/GenericAllStats';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
@@ -7,7 +8,6 @@ import TierWeights from '../components/TierWeights';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { getClanLogo } from '../core/blitz/getClanLogo';
|
||||
import { getPlayerClanInfo } from '../core/blitz/getPlayerClanInfo';
|
||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||
import { getTierWeights } from '../core/blitzkrieg/getTierWeights';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
@@ -37,7 +37,7 @@ async function render(
|
||||
filters: StatFilters,
|
||||
) {
|
||||
const { nickname } = await getAccountInfo(region, id);
|
||||
const clan = (await getPlayerClanInfo(region, id))[id]?.clan;
|
||||
const clan = (await getClanAccountInfo(region, id))?.clan;
|
||||
const clanImage = clan ? getClanLogo(clan.emblem_set_id) : undefined;
|
||||
const diffedTankStats = await getDiffedTankStats(region, id, start, end);
|
||||
const { stats, supplementary, filteredOrder } = await filterStats(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo';
|
||||
import { StatFilters, filterStats } from '../_core/statistics/filterStats';
|
||||
import AllStatsOverview from '../components/AllStatsOverview';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { getClanLogo } from '../core/blitz/getClanLogo';
|
||||
import { getPlayerClanInfo } from '../core/blitz/getPlayerClanInfo';
|
||||
import { filtersToDescription } from '../core/blitzkrieg/filtersToDescription';
|
||||
import { getBlitzStarsLinkButton } from '../core/blitzstars/getBlitzStarsLinkButton';
|
||||
import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats';
|
||||
@@ -34,8 +34,8 @@ async function render(
|
||||
{ start, end, name }: ResolvedPeriod,
|
||||
filters: StatFilters,
|
||||
) {
|
||||
const nickname = (await getAccountInfo(region, id))[id].nickname;
|
||||
const clan = (await getPlayerClanInfo(region, id))[id]?.clan;
|
||||
const { nickname } = await getAccountInfo(region, id);
|
||||
const clan = (await getClanAccountInfo(region, 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);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import { getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import interactionToURL from '../core/discord/interactionToURL';
|
||||
@@ -10,7 +9,6 @@ import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import today from '../renderers/today';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
export const todayCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
@@ -50,11 +48,7 @@ export const todayCommand: CommandRegistry = {
|
||||
const cutoff = interaction.options.getInteger('cutoff') ?? undefined;
|
||||
const maximized = interaction.options.getInteger('maximized') ?? undefined;
|
||||
const showTotal = interaction.options.getBoolean('show-total') ?? undefined;
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`,
|
||||
)
|
||||
)[player.id];
|
||||
const { nickname } = await getAccountInfo(player.region, player.id);
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
cutoff,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AllStats, SupplementaryStats } from '../../types/accountInfo';
|
||||
import { AllStats, SupplementaryStats } from '../../_core/blitz/getAccountInfo';
|
||||
import { WN8Display } from './components/WN8Display';
|
||||
import {
|
||||
WN8SurroundingStat,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AllStats, SupplementaryStats } from '../../_core/blitz/getAccountInfo';
|
||||
import getWN8Percentile from '../../core/blitz/getWN8Percentile';
|
||||
import isNumber from '../../core/node/isNumber';
|
||||
import { AllStats, SupplementaryStats } from '../../types/accountInfo';
|
||||
import { Card } from './components/Card';
|
||||
import { Root } from './components/Root';
|
||||
import { Row } from './components/Row';
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { PlayerClanInfo } from '../../types/playerClanData';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export function getPlayerClanInfo(region: Region, id: number) {
|
||||
return getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
import { AllStats } from '../../_core/blitz/getAccountInfo';
|
||||
import { emptyAllStats } from '../blitzstars/getDiffedTankStats';
|
||||
|
||||
export default function sumStats(allStatsCollection: AllStats[]) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AllStats } from '../../_core/blitz/getAccountInfo';
|
||||
import { TierWeightsRecord } from '../../components/TierWeights';
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
import { tankopedia } from '../blitz/tankopedia';
|
||||
|
||||
export async function getTierWeights(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { getAccountInfo } from '../../_core/blitz/getAccountInfo';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { AccountInfo } from '../../types/accountInfo';
|
||||
import getWargamingResponse from '../blitz/getWargamingResponse';
|
||||
import linkButton from '../discord/linkButton';
|
||||
|
||||
export async function getBlitzStarsLinkButton(
|
||||
@@ -9,11 +7,7 @@ export async function getBlitzStarsLinkButton(
|
||||
id: number,
|
||||
tankId?: number,
|
||||
) {
|
||||
const { nickname } = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
)[id];
|
||||
const { nickname } = await getAccountInfo(region, id);
|
||||
|
||||
return linkButton(
|
||||
`https://www.blitzstars.com/player/${region}/${nickname}${
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AllStats } from '../../_core/blitz/getAccountInfo';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
import getTankHistories, {
|
||||
TankHistories,
|
||||
TankHistoryRaw,
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { getAccountInfo } from '../../_core/blitz/getAccountInfo';
|
||||
import { PlayerStats } from '../../_core/blitzstars/getPlayerStats';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { AccountInfo } from '../../types/accountInfo';
|
||||
import {
|
||||
GetHistoriesOptions,
|
||||
Histories,
|
||||
History,
|
||||
getHistoriesDefaultOptions,
|
||||
} from '../../types/histories';
|
||||
import getWargamingResponse from '../blitz/getWargamingResponse';
|
||||
import { emptyAllStats } from './getDiffedTankStats';
|
||||
|
||||
export default async function getPlayerHistories(
|
||||
@@ -19,7 +18,7 @@ export default async function getPlayerHistories(
|
||||
const response = await fetch(
|
||||
`https://www.blitzstars.com/api/playerstats/${id}`,
|
||||
);
|
||||
const playerHistories = ((await response.json()) as PlayerHistoriesRaw).map(
|
||||
const playerHistories = ((await response.json()) as PlayerStats).map(
|
||||
(history) =>
|
||||
({
|
||||
all: history.statistics.all,
|
||||
@@ -42,16 +41,9 @@ export default async function getPlayerHistories(
|
||||
const latestNodes: Histories = [];
|
||||
|
||||
if (mergedOptions.includeLatestHistories) {
|
||||
const {
|
||||
last_battle_time,
|
||||
statistics: { all },
|
||||
} = (
|
||||
await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
)[id];
|
||||
const { last_battle_time, statistics } = await getAccountInfo(server, id);
|
||||
|
||||
latestNodes.push({ all, last_battle_time });
|
||||
latestNodes.push({ all: statistics.all, last_battle_time });
|
||||
}
|
||||
|
||||
const previousNodes: Histories = [];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
import { AllStats } from '../../_core/blitz/getAccountInfo';
|
||||
import { context } from '../blitzkrieg/context';
|
||||
|
||||
export interface SpecialStats {
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
} from 'discord.js';
|
||||
import discord from '../../../discord.json' assert { type: 'json' };
|
||||
import { aboutCommand } from '../../commands/about';
|
||||
import { clanEventCommand } from '../../commands/clanEvent';
|
||||
import { debugCommand } from '../../commands/debug';
|
||||
import { eligibleCommand } from '../../commands/eligible';
|
||||
import { evolutionCommand } from '../../commands/evolution';
|
||||
@@ -102,7 +101,6 @@ export const COMMANDS_RAW: CommandRegistry[] = [
|
||||
evolutionCommand,
|
||||
statsCommand,
|
||||
ratingsCommand,
|
||||
clanEventCommand,
|
||||
];
|
||||
|
||||
export const commands = Promise.all(COMMANDS_RAW).then((rawCommands) =>
|
||||
|
||||
+9
-15
@@ -1,13 +1,13 @@
|
||||
import { AllStats, getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
import { getClanAccountInfo } from '../_core/blitz/getClanAccountInfo';
|
||||
import calculateWN8 from '../_core/statistics/calculateWN8';
|
||||
import * as Breakdown from '../components/Breakdown';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
import TitleBar from '../components/TitleBar';
|
||||
import Wrapper from '../components/Wrapper';
|
||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||
import calculateWN8 from '../core/blitz/calculateWN8';
|
||||
import getTankStats from '../core/blitz/getTankStats';
|
||||
import getTreeType from '../core/blitz/getTreeType';
|
||||
import getWN8Percentile from '../core/blitz/getWN8Percentile';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import resolveTankName from '../core/blitz/resolveTankName';
|
||||
import sumStats from '../core/blitz/sumStats';
|
||||
import { tankopedia } from '../core/blitz/tankopedia';
|
||||
@@ -16,8 +16,6 @@ import getPeriodNow from '../core/blitzstars/getPeriodNow';
|
||||
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
||||
import { tankAverages } from '../core/blitzstars/tankAverages';
|
||||
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo';
|
||||
import { PlayerClanInfo } from '../types/playerClanData';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export default async function today(
|
||||
@@ -33,16 +31,12 @@ export default async function today(
|
||||
getTimeDaysAgo(server, 1),
|
||||
getPeriodNow(),
|
||||
);
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
const clanData = await getWargamingResponse<PlayerClanInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`,
|
||||
);
|
||||
const accountInfo = await getAccountInfo(server, id);
|
||||
const clanData = await getClanAccountInfo(server, id);
|
||||
const careerTankStatsRaw = await getTankStats(server, id);
|
||||
const careerStats: Record<number, AllStats> = showTotal
|
||||
? {
|
||||
0: accountInfo[id].statistics.all,
|
||||
0: accountInfo.statistics.all,
|
||||
}
|
||||
: {};
|
||||
const allStatsToAccumulate: AllStats[] = [];
|
||||
@@ -191,10 +185,10 @@ export default async function today(
|
||||
) : (
|
||||
<Wrapper>
|
||||
<TitleBar
|
||||
name={accountInfo[id].nickname}
|
||||
name={accountInfo.nickname}
|
||||
image={
|
||||
clanData[id]?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData[id]?.clan?.emblem_set_id}.png`
|
||||
clanData?.clan
|
||||
? `https://wotblitz-gc.gcdn.co/icons/clanEmblems1x/clan-icon-v2-${clanData?.clan?.emblem_set_id}.png`
|
||||
: undefined
|
||||
}
|
||||
description="Today's breakdown"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// a cleaner simplification of Blitz Stars' histories because it's a mess there
|
||||
|
||||
import { AllStats } from './accountInfo';
|
||||
import { AllStats } from '../_core/blitz/getAccountInfo';
|
||||
|
||||
export interface History {
|
||||
all: AllStats;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AllStats } from './accountInfo';
|
||||
import { AllStats } from '../_core/blitz/getAccountInfo';
|
||||
|
||||
export interface IndividualTankStats {
|
||||
all: AllStats;
|
||||
|
||||
Reference in new issue
Block a user