diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index 815c10a73..6390302f4 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -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, { diff --git a/src/commands/fullStats.tsx b/src/commands/fullStats.tsx index 21c17740e..08903fa3e 100644 --- a/src/commands/fullStats.tsx +++ b/src/commands/fullStats.tsx @@ -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( diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index fa769167a..0c9ad0f76 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -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); diff --git a/src/commands/today.tsx b/src/commands/today.tsx index f1b77309e..a77c0dfb2 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -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( - `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, diff --git a/src/components/AllStatsOverview/index.tsx b/src/components/AllStatsOverview/index.tsx index da7ba6c34..e78774e9d 100644 --- a/src/components/AllStatsOverview/index.tsx +++ b/src/components/AllStatsOverview/index.tsx @@ -1,4 +1,4 @@ -import { AllStats, SupplementaryStats } from '../../types/accountInfo'; +import { AllStats, SupplementaryStats } from '../../_core/blitz/getAccountInfo'; import { WN8Display } from './components/WN8Display'; import { WN8SurroundingStat, diff --git a/src/components/GenericAllStats/index.tsx b/src/components/GenericAllStats/index.tsx index 3919b7c14..fa75bfe4c 100644 --- a/src/components/GenericAllStats/index.tsx +++ b/src/components/GenericAllStats/index.tsx @@ -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'; diff --git a/src/core/blitz/getPlayerClanInfo.ts b/src/core/blitz/getPlayerClanInfo.ts deleted file mode 100644 index db30e7f0a..000000000 --- a/src/core/blitz/getPlayerClanInfo.ts +++ /dev/null @@ -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( - `https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`, - ); -} diff --git a/src/core/blitz/sumStats.ts b/src/core/blitz/sumStats.ts index 160ddf593..63a002b37 100644 --- a/src/core/blitz/sumStats.ts +++ b/src/core/blitz/sumStats.ts @@ -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[]) { diff --git a/src/core/blitzkrieg/getTierWeights.ts b/src/core/blitzkrieg/getTierWeights.ts index 4140c4164..cf4a079ea 100644 --- a/src/core/blitzkrieg/getTierWeights.ts +++ b/src/core/blitzkrieg/getTierWeights.ts @@ -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( diff --git a/src/core/blitzstars/getBlitzStarsLinkButton.ts b/src/core/blitzstars/getBlitzStarsLinkButton.ts index 9fdaf152d..78e0388f8 100644 --- a/src/core/blitzstars/getBlitzStarsLinkButton.ts +++ b/src/core/blitzstars/getBlitzStarsLinkButton.ts @@ -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( - `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}${ diff --git a/src/core/blitzstars/getDiffedTankStats.ts b/src/core/blitzstars/getDiffedTankStats.ts index 512a52692..dc571d972 100644 --- a/src/core/blitzstars/getDiffedTankStats.ts +++ b/src/core/blitzstars/getDiffedTankStats.ts @@ -1,5 +1,5 @@ +import { AllStats } from '../../_core/blitz/getAccountInfo'; import { Region } from '../../constants/regions'; -import { AllStats } from '../../types/accountInfo'; import getTankHistories, { TankHistories, TankHistoryRaw, diff --git a/src/core/blitzstars/getPlayerHistories.ts b/src/core/blitzstars/getPlayerHistories.ts index 13bcbd674..c546c3907 100644 --- a/src/core/blitzstars/getPlayerHistories.ts +++ b/src/core/blitzstars/getPlayerHistories.ts @@ -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( - `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 = []; diff --git a/src/core/blitzstars/tankAverages.ts b/src/core/blitzstars/tankAverages.ts index 8fd37a864..23d5599ee 100644 --- a/src/core/blitzstars/tankAverages.ts +++ b/src/core/blitzstars/tankAverages.ts @@ -1,4 +1,4 @@ -import { AllStats } from '../../types/accountInfo'; +import { AllStats } from '../../_core/blitz/getAccountInfo'; import { context } from '../blitzkrieg/context'; export interface SpecialStats { diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index f218d5c7a..a461732ab 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -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) => diff --git a/src/renderers/today.tsx b/src/renderers/today.tsx index baf7cfb96..d4a908e2c 100644 --- a/src/renderers/today.tsx +++ b/src/renderers/today.tsx @@ -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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, - ); - const clanData = await getWargamingResponse( - `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 = showTotal ? { - 0: accountInfo[id].statistics.all, + 0: accountInfo.statistics.all, } : {}; const allStatsToAccumulate: AllStats[] = []; @@ -191,10 +185,10 @@ export default async function today( ) : (