From e37e0ccf9f454fc6466a9d55bc982e541d5eda5f Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 23 Sep 2023 21:51:00 +0000 Subject: [PATCH] feat: made WARGAMING_APPLICATION_ID public --- .github/workflows/cd-host.yml | 2 +- src/app/tools/session/page.tsx | 36 ++++++++++--- src/commands/clanEvent.ts | 8 +-- src/commands/eligible.ts | 4 +- src/commands/evolution.tsx | 4 +- src/commands/fullStats.tsx | 4 +- src/commands/inactive.tsx | 10 ++-- src/commands/ownedTanks.tsx | 6 +-- src/commands/playerAchievements.ts | 6 +-- src/commands/playerInfo.ts | 4 +- src/commands/ratings.tsx | 10 ++-- src/commands/searchClans.ts | 4 +- src/commands/searchPlayers.ts | 8 +-- src/commands/stats.tsx | 4 +- src/commands/today.tsx | 4 +- src/commands/verify.ts | 6 +-- src/components/Breakdown/index.ts | 1 - src/constants/wargamingApplicationID.ts | 2 + src/core/blitz/diffNormalizedTankStats.ts | 66 +++++++++++++++++++++++ src/core/blitz/getTankStats.ts | 4 +- src/core/blitz/listClans.ts | 8 +-- src/core/blitz/listPlayers.ts | 8 +-- src/core/blitz/tankopedia.ts | 4 +- src/core/blitzstars/getDiffedTankStats.ts | 1 + src/core/blitzstars/getPlayerHistories.ts | 4 +- src/core/node/secrets.ts | 6 +-- src/renderers/evolution.tsx | 5 +- src/renderers/fullStats.tsx | 5 +- src/renderers/stats.tsx | 5 +- src/renderers/today.tsx | 5 +- src/types/tanksStats.ts | 32 +++++++++++ 31 files changed, 196 insertions(+), 80 deletions(-) create mode 100644 src/constants/wargamingApplicationID.ts create mode 100644 src/core/blitz/diffNormalizedTankStats.ts diff --git a/.github/workflows/cd-host.yml b/.github/workflows/cd-host.yml index b8ea6ff8d..b6285d922 100644 --- a/.github/workflows/cd-host.yml +++ b/.github/workflows/cd-host.yml @@ -29,4 +29,4 @@ jobs: unzip bot.zip - name: Run bot - run: NODE_ENV=production GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} node --enable-source-maps --trace-warnings bot/index.cjs + run: NODE_ENV=production GH_TOKEN=${{ secrets.GH_TOKEN }} DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ WARGAMING_APPLICATION_ID }} node --enable-source-maps --trace-warnings bot/index.cjs diff --git a/src/app/tools/session/page.tsx b/src/app/tools/session/page.tsx index f14f304ee..b3b06d94c 100644 --- a/src/app/tools/session/page.tsx +++ b/src/app/tools/session/page.tsx @@ -2,15 +2,20 @@ import { CopyIcon, ListBulletIcon, ReloadIcon } from '@radix-ui/react-icons'; import { debounce } from 'lodash'; -import { ChangeEvent, useRef, useState } from 'react'; +import { ChangeEvent, useEffect, useRef, useState } from 'react'; +import * as Breakdown from '../../../components/Breakdown'; import { Button } from '../../../components/Button'; import PageWrapper from '../../../components/PageWrapper'; import { SearchBar } from '../../../components/SearchBar'; import { REGION_NAMES } from '../../../constants/regions'; +import { diffNormalizedTankStats } from '../../../core/blitz/diffNormalizedTankStats'; import { AccountListWithServer } from '../../../core/blitz/listPlayers'; import { theme } from '../../../stitches.config'; import { useSession } from '../../../stores/session'; -import { NormalizedTankStats } from '../../../types/tanksStats'; +import { + IndividualTankStats, + NormalizedTankStats, +} from '../../../types/tanksStats'; import * as styles from './page.css'; export default function Page() { @@ -33,7 +38,21 @@ export default function Page() { }, 500, ); - const initialSession = useSession.getState(); + const session = useSession(); + const [diff, setDiff] = useState(undefined); + + useEffect(() => { + (async () => { + if (session.isTracking) { + const { id, region } = session; + const current = await fetch( + `/api/stats/normalized/tanks?id=${id}®ion=${region}`, + ).then((response) => response.json() as Promise); + + setDiff(diffNormalizedTankStats(session.tankStats, current)); + } + })(); + }, []); return ( @@ -42,9 +61,7 @@ export default function Page() { { if (event.target.value) { setShowSearchResults(true); @@ -175,6 +192,13 @@ export default function Page() { + + + {diff && + (Object.entries(diff) as [string, IndividualTankStats][]) + .sort(([, a], [, b]) => b.last_battle_time - a.last_battle_time) + .map(([id, tankStats]) => )} + ); } diff --git a/src/commands/clanEvent.ts b/src/commands/clanEvent.ts index 101c5b85f..2b06e8dfc 100644 --- a/src/commands/clanEvent.ts +++ b/src/commands/clanEvent.ts @@ -1,5 +1,6 @@ import { SlashCommandBuilder, escapeMarkdown } from 'discord.js'; import markdownEscape from 'markdown-escape'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import { PlayerHistoriesRaw } from '../core/blitzstars/getPlayerHistories'; import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo'; @@ -7,7 +8,6 @@ import addClanChoices from '../core/discord/addClanChoices'; import autocompleteClan from '../core/discord/autocompleteClan'; import embedWarning from '../core/discord/embedWarning'; import resolveClanFromCommand from '../core/discord/resolveClanFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountAchievements } from '../types/accountAchievements'; import { AccountInfo } from '../types/accountInfo'; @@ -26,16 +26,16 @@ export const clanEventCommand: CommandRegistry = { const { region, id } = await resolveClanFromCommand(interaction); const clan = ( await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&clan_id=${id}`, + `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`, ) )[id]; const memberIds = clan.members_ids.join(','); const [players, achievements, previousJointVictories] = await Promise.all([ getWargamingResponse( - `https://api.wotblitz.${region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${memberIds}`, + `https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`, ), getWargamingResponse( - `https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${memberIds}`, + `https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`, ), Promise.all( clan.members_ids.map((id) => diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 619f31af4..bd89200d5 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import calculateWN8 from '../core/blitz/calculateWN8'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import sumStats from '../core/blitz/sumStats'; @@ -12,7 +13,6 @@ import embedNegative from '../core/discord/embedNegative'; import embedPositive from '../core/discord/embedPositive'; import markdownTable, { TableInput } from '../core/discord/markdownTable'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; import { PossiblyPromise } from '../types/possiblyPromise'; @@ -50,7 +50,7 @@ export const eligibleCommand: CommandRegistry = { const clan = interaction.options.getString('clan') as SkilledClan; const { id, region: server } = await resolvePlayerFromCommand(interaction); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const problems: TableInput = []; const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`; diff --git a/src/commands/evolution.tsx b/src/commands/evolution.tsx index 2bab316f7..1b39ef3b9 100644 --- a/src/commands/evolution.tsx +++ b/src/commands/evolution.tsx @@ -1,5 +1,6 @@ import { SlashCommandBuilder } from 'discord.js'; import { CYCLIC_API } from '../constants/cyclic'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import resolveTankId from '../core/blitz/resolveTankId'; import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups'; @@ -12,7 +13,6 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistryRaw } from '../events/interactionCreate'; import evolution from '../renderers/evolution'; import { StatType } from '../renderers/stats'; @@ -46,7 +46,7 @@ export const evolutionCommand = new Promise( const end = interaction.options.getInteger('end'); const { nickname } = ( await getWargamingResponse( - `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`, + `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`, ) )[player.id]; const path = interactionToURL(interaction, { diff --git a/src/commands/fullStats.tsx b/src/commands/fullStats.tsx index bbfef0c27..d1c10afb7 100644 --- a/src/commands/fullStats.tsx +++ b/src/commands/fullStats.tsx @@ -1,6 +1,7 @@ import { SlashCommandBuilder } from 'discord.js'; import { TreeTypeString } from '../components/Tanks'; import { CYCLIC_API } from '../constants/cyclic'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import resolveTankId from '../core/blitz/resolveTankId'; import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups'; @@ -13,7 +14,6 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistryRaw } from '../events/interactionCreate'; import fullStats from '../renderers/fullStats'; import { MultiTankFilters, StatType } from '../renderers/stats'; @@ -57,7 +57,7 @@ export const fullStatsCommand = new Promise( }); const { nickname } = ( await getWargamingResponse( - `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`, + `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`, ) )[player.id]; diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index f453d9c64..7b14b5ea5 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -3,11 +3,11 @@ import GenericStats from '../components/GenericStats'; import NoData, { NoDataType } from '../components/NoData'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addClanChoices from '../core/discord/addClanChoices'; import autocompleteClan from '../core/discord/autocompleteClan'; import resolveClanFromCommand from '../core/discord/resolveClanFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; import { ClanInfo } from '../types/clanInfo'; @@ -38,14 +38,14 @@ export const inactiveCommand: CommandRegistry = { const time = new Date().getTime() / 1000; const clanData = ( await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&clan_id=${id}`, + `https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`, ) )[id]; const memberIds = clanData.members_ids; const accounts = await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/account/info/?application_id=${ - secrets.WARGAMING_APPLICATION_ID - }&account_id=${memberIds.join(',')}`, + `https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds.join( + ',', + )}`, ); const inactive = memberIds .map((memberId) => { diff --git a/src/commands/ownedTanks.tsx b/src/commands/ownedTanks.tsx index 3fbd82023..a8bd2e0cb 100644 --- a/src/commands/ownedTanks.tsx +++ b/src/commands/ownedTanks.tsx @@ -3,6 +3,7 @@ import NoData, { NoDataType } from '../components/NoData'; import * as Tanks from '../components/Tanks'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getTankStats from '../core/blitz/getTankStats'; import getTreeType from '../core/blitz/getTreeType'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; @@ -18,7 +19,6 @@ import addTierChoices from '../core/discord/addTierChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; import { PlayerClanData } from '../types/playerClanData'; @@ -59,7 +59,7 @@ export const ownedTanksCommand: CommandRegistry = { const account = await resolvePlayerFromCommand(interaction); const { id, region: server } = account; const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const tankStats = await getTankStats(server, id); const filteredTanks = ( @@ -71,7 +71,7 @@ export const ownedTanksCommand: CommandRegistry = { ) ).filter((tank) => tank.tankopedia?.tier === tier); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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 = {}; const nations: string[] = []; diff --git a/src/commands/playerAchievements.ts b/src/commands/playerAchievements.ts index e6f178238..91baffa25 100644 --- a/src/commands/playerAchievements.ts +++ b/src/commands/playerAchievements.ts @@ -1,13 +1,13 @@ import { SlashCommandBuilder } from 'discord.js'; import { startCase } from 'lodash'; import markdownEscape from 'markdown-escape'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; import embedInfo from '../core/discord/embedInfo'; import markdownTable, { TableInputEntry } from '../core/discord/markdownTable'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountAchievements } from '../types/accountAchievements'; import { AccountInfo } from '../types/accountInfo'; @@ -37,11 +37,11 @@ export const playerAchievementsCommand: CommandRegistry = { const account = await resolvePlayerFromCommand(interaction); const { id, region: server } = account; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountsAchievements = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountAchievements = accountsAchievements[id]; const compound = { diff --git a/src/commands/playerInfo.ts b/src/commands/playerInfo.ts index c65c181cf..f85908394 100644 --- a/src/commands/playerInfo.ts +++ b/src/commands/playerInfo.ts @@ -1,12 +1,12 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; import embedInfo from '../core/discord/embedInfo'; import markdownTable from '../core/discord/markdownTable'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; @@ -23,7 +23,7 @@ export const playerInfoCommand: CommandRegistry = { const account = await resolvePlayerFromCommand(interaction); const { id, region: server } = account; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountInfo = accounts[id]; diff --git a/src/commands/ratings.tsx b/src/commands/ratings.tsx index 620df28bb..ac895b837 100644 --- a/src/commands/ratings.tsx +++ b/src/commands/ratings.tsx @@ -9,6 +9,7 @@ import * as Leaderboard from '../components/Leaderboard'; import TitleBar from '../components/TitleBar'; import Wrapper from '../components/Wrapper'; import { REGION_NAMES_SHORT, Region } from '../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getArchivedRatingsInfo from '../core/blitz/getArchivedRatingsInfo'; import getRatingsInfo from '../core/blitz/getRatingsInfo'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; @@ -21,7 +22,6 @@ import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; import { octokit } from '../core/express/octokit'; -import { secrets } from '../core/node/secrets'; import throwError from '../core/node/throwError'; import { CommandRegistryRaw } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; @@ -307,7 +307,7 @@ export const ratingsCommand = new Promise( ); const ids = trimmed.map((player) => player.id).join(','); const clanData = await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.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`, ); return trimmed.map( @@ -371,11 +371,11 @@ export const ratingsCommand = new Promise( )) as RatingsInfo; }); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const clan = ( await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.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; const regionSubdomain = regionToRegionSubdomain(region); @@ -438,7 +438,7 @@ export const ratingsCommand = new Promise( ); const ids = trimmed.map((player) => player.id).join(','); const clanData = await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/clans/accountinfo/?application_id=${secrets.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`, ); return trimmed.map((player, index) => ({ diff --git a/src/commands/searchClans.ts b/src/commands/searchClans.ts index f02e70fc4..28016ce85 100644 --- a/src/commands/searchClans.ts +++ b/src/commands/searchClans.ts @@ -1,11 +1,11 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { REGION_NAMES, Region } from '../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addClanChoices from '../core/discord/addClanChoices'; import addRegionChoices from '../core/discord/addRegionChoices'; import embedInfo from '../core/discord/embedInfo'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { ClanList } from '../types/clanList'; @@ -31,7 +31,7 @@ export const searchClansCommand: CommandRegistry = { const clan = interaction.options.getString('clan')!; const limit = interaction.options.getInteger('limit') ?? 25; const clanList = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, + `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, ); return embedInfo( diff --git a/src/commands/searchPlayers.ts b/src/commands/searchPlayers.ts index 645ba217e..0f43f871c 100644 --- a/src/commands/searchPlayers.ts +++ b/src/commands/searchPlayers.ts @@ -1,12 +1,12 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import { REGION_NAMES, Region } from '../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import { usernamePattern } from '../core/blitz/listPlayers'; import addRegionChoices from '../core/discord/addRegionChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import embedInfo from '../core/discord/embedInfo'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountList } from '../types/accountList'; @@ -36,9 +36,9 @@ export const searchPlayersCommand: CommandRegistry = { const trimmedSearch = name.trim(); const players = usernamePattern.test(trimmedSearch) ? await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/list/?application_id=${ - secrets.WARGAMING_APPLICATION_ID - }&search=${encodeURIComponent(trimmedSearch)}&limit=${limit}`, + `https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent( + trimmedSearch, + )}&limit=${limit}`, ) : []; diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index ee3b1cfc2..60f1dcc9c 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -1,6 +1,7 @@ import { SlashCommandBuilder } from 'discord.js'; import { TreeTypeString } from '../components/Tanks'; import { CYCLIC_API } from '../constants/cyclic'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import resolveTankId from '../core/blitz/resolveTankId'; import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups'; @@ -13,7 +14,6 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistryRaw } from '../events/interactionCreate'; import stats, { MultiTankFilters, StatType } from '../renderers/stats'; import { AccountInfo } from '../types/accountInfo'; @@ -55,7 +55,7 @@ export const statsCommand = new Promise(async (resolve) => { }); const { nickname } = ( await getWargamingResponse( - `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`, + `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`, ) )[player.id]; diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 6d3a90dc6..48d658056 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -1,4 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; @@ -7,7 +8,6 @@ import linkButton from '../core/discord/linkButton'; import primaryButton from '../core/discord/primaryButton'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import today from '../renderers/today'; import { AccountInfo } from '../types/accountInfo'; @@ -52,7 +52,7 @@ export const todayCommand: CommandRegistry = { const showTotal = interaction.options.getBoolean('show-total') ?? undefined; const { nickname } = ( await getWargamingResponse( - `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${player.id}`, + `https://api.wotblitz.${player.region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${player.id}`, ) )[player.id]; const path = interactionToURL(interaction, { diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 560afb22a..70524c432 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -1,13 +1,13 @@ import { SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; import discord from '../../discord.json' assert { type: 'json' }; +import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID'; import getWargamingResponse from '../core/blitz/getWargamingResponse'; import addUsernameChoices from '../core/discord/addUsernameChoices'; import autocompleteUsername from '../core/discord/autocompleteUsername'; import embedNegative from '../core/discord/embedNegative'; import embedPositive from '../core/discord/embedPositive'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { CommandRegistry } from '../events/interactionCreate'; import { AccountInfo } from '../types/accountInfo'; import { PlayerClanData } from '../types/playerClanData'; @@ -25,10 +25,10 @@ export const verifyCommand: CommandRegistry = { const blitzAccount = await resolvePlayerFromCommand(interaction); const { id, region: server } = blitzAccount; const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.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( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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 clan = clanData[id]?.clan; const clanTag = clan ? ` [${clan!.tag}]` : ''; diff --git a/src/components/Breakdown/index.ts b/src/components/Breakdown/index.ts index c2782754b..bf85c5f20 100644 --- a/src/components/Breakdown/index.ts +++ b/src/components/Breakdown/index.ts @@ -1,4 +1,3 @@ export * from './components/Root'; export * from './components/Row'; export * from './components/RowStat'; - diff --git a/src/constants/wargamingApplicationID.ts b/src/constants/wargamingApplicationID.ts new file mode 100644 index 000000000..fb071737b --- /dev/null +++ b/src/constants/wargamingApplicationID.ts @@ -0,0 +1,2 @@ +// if you forked this repository, please replace this with your own id +export const WARGAMING_APPLICATION_ID = 'd03364bdc9114fc61f1d5e4e168d5f3c'; diff --git a/src/core/blitz/diffNormalizedTankStats.ts b/src/core/blitz/diffNormalizedTankStats.ts new file mode 100644 index 000000000..35f4a26c2 --- /dev/null +++ b/src/core/blitz/diffNormalizedTankStats.ts @@ -0,0 +1,66 @@ +import { + IndividualTankStats, + NormalizedTankStats, + emptyIndividualTankStats, +} from '../../types/tanksStats'; + +export function diffNormalizedTankStats( + a: NormalizedTankStats, + b: NormalizedTankStats, +) { + const bTanks = Object.keys(b); + const changedTanks = bTanks.filter((id) => { + return ( + a[id as unknown as number]?.all.battles !== + b[id as unknown as number].all.battles + ); + }); + const diff = changedTanks.map((id) => { + const aTank = a[id as unknown as number] ?? emptyIndividualTankStats; + const bTank = b[id as unknown as number]; + + const tankDiff = { + account_id: bTank.account_id, + battle_life_time: bTank.battle_life_time, + frags: (bTank.frags ?? aTank.frags ?? 0) - (aTank.frags ?? 0), + max_frags: Math.max(aTank.max_frags, bTank.max_frags), + in_garage: bTank.in_garage, + max_xp: Math.max(aTank.max_xp, bTank.max_xp), + in_garage_updated: bTank.in_garage_updated, + last_battle_time: bTank.last_battle_time - aTank.last_battle_time, + mark_of_mastery: bTank.mark_of_mastery, + tank_id: bTank.tank_id, + + all: { + battles: bTank.all.battles - aTank.all.battles, + wins: bTank.all.wins - aTank.all.wins, + capture_points: bTank.all.capture_points - aTank.all.capture_points, + damage_dealt: bTank.all.damage_dealt - aTank.all.damage_dealt, + damage_received: bTank.all.damage_received - aTank.all.damage_received, + dropped_capture_points: + bTank.all.dropped_capture_points - aTank.all.dropped_capture_points, + frags: bTank.all.frags - aTank.all.frags, + frags8p: bTank.all.frags8p - aTank.all.frags8p, + hits: bTank.all.hits - aTank.all.hits, + losses: bTank.all.losses - aTank.all.losses, + max_frags: Math.max(aTank.max_frags, bTank.max_frags), + max_xp: Math.max(aTank.max_xp, bTank.max_xp), + shots: bTank.all.shots - aTank.all.shots, + spotted: bTank.all.spotted - aTank.all.spotted, + survived_battles: + bTank.all.survived_battles - aTank.all.survived_battles, + win_and_survived: + bTank.all.win_and_survived - aTank.all.win_and_survived, + xp: bTank.all.xp - aTank.all.xp, + }, + } satisfies IndividualTankStats; + + return tankDiff; + }); + const normalized = diff.reduce( + (accumulator, diff) => ({ ...accumulator, [diff.tank_id]: diff }), + {}, + ); + + return normalized; +} diff --git a/src/core/blitz/getTankStats.ts b/src/core/blitz/getTankStats.ts index bdf6a84eb..9f57e627e 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/core/blitz/getTankStats.ts @@ -1,12 +1,12 @@ import { REGION_NAMES, Region } from '../../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import { TankStats } from '../../types/tanksStats'; -import { secrets } from '../node/secrets'; import throwError from '../node/throwError'; import getWargamingResponse from './getWargamingResponse'; export default async function getTankStats(region: Region, id: number) { const tankStats = await getWargamingResponse( - `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); if (tankStats[id] === null) { diff --git a/src/core/blitz/listClans.ts b/src/core/blitz/listClans.ts index b2e99d0dc..a0475bd62 100644 --- a/src/core/blitz/listClans.ts +++ b/src/core/blitz/listClans.ts @@ -1,6 +1,6 @@ import { Region } from '../../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import { Clan, ClanList } from '../../types/clanList'; -import { secrets } from '../node/secrets'; import getWargamingResponse from './getWargamingResponse'; export type ClanListWithRegion = (Clan & { @@ -15,7 +15,7 @@ export default async function listClans(search: string, limit = 9) { return ( await Promise.all([ getWargamingResponse( - `https://api.wotblitz.com/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -25,7 +25,7 @@ export default async function listClans(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -35,7 +35,7 @@ export default async function listClans(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/blitz/listPlayers.ts b/src/core/blitz/listPlayers.ts index ac803795f..fa419bbcb 100644 --- a/src/core/blitz/listPlayers.ts +++ b/src/core/blitz/listPlayers.ts @@ -1,5 +1,5 @@ import { Region } from '../../constants/regions'; -import { secrets } from '../node/secrets'; +import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import getWargamingResponse from './getWargamingResponse'; interface Account { @@ -23,7 +23,7 @@ export default async function listPlayers(search: string, limit = 9) { return ( await Promise.all([ getWargamingResponse( - `https://api.wotblitz.com/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -33,7 +33,7 @@ export default async function listPlayers(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -43,7 +43,7 @@ export default async function listPlayers(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/account/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/blitz/tankopedia.ts b/src/core/blitz/tankopedia.ts index b59821db5..d9762500c 100644 --- a/src/core/blitz/tankopedia.ts +++ b/src/core/blitz/tankopedia.ts @@ -1,5 +1,5 @@ import { deburr } from 'lodash'; -import { secrets } from '../node/secrets'; +import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import getWargamingResponse from './getWargamingResponse'; export type TankType = 'AT-SPG' | 'lightTank' | 'mediumTank' | 'heavyTank'; @@ -66,7 +66,7 @@ export interface TankopediaInfo { // this is blocking because info is needed for command creation console.log('Caching tankopedia info...'); export const tankopediaInfo = getWargamingResponse( - `https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}`, + `https://api.wotblitz.com/wotb/encyclopedia/info/?application_id=${WARGAMING_APPLICATION_ID}`, ); console.log('Cached tankopedia info'); diff --git a/src/core/blitzstars/getDiffedTankStats.ts b/src/core/blitzstars/getDiffedTankStats.ts index 68bb54618..ccf0f2099 100644 --- a/src/core/blitzstars/getDiffedTankStats.ts +++ b/src/core/blitzstars/getDiffedTankStats.ts @@ -34,6 +34,7 @@ export const emptyTankHistoryNode: TankHistoryRaw = { all: emptyAllStats, }; +// BIG TODO: merge this neatly with diffNormalizedTankStats export default async function getDiffedTankStats( server: Region, id: number, diff --git a/src/core/blitzstars/getPlayerHistories.ts b/src/core/blitzstars/getPlayerHistories.ts index 0c04357c0..7d5915ec5 100644 --- a/src/core/blitzstars/getPlayerHistories.ts +++ b/src/core/blitzstars/getPlayerHistories.ts @@ -1,4 +1,5 @@ import { Region } from '../../constants/regions'; +import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID'; import { AccountInfo, AllStats } from '../../types/accountInfo'; import { GetHistoriesOptions, @@ -7,7 +8,6 @@ import { getHistoriesDefaultOptions, } from '../../types/histories'; import getWargamingResponse from '../blitz/getWargamingResponse'; -import { secrets } from '../node/secrets'; import { emptyAllStats } from './getDiffedTankStats'; export interface PlayerHistoryRaw { @@ -67,7 +67,7 @@ export default async function getPlayerHistories( statistics: { all }, } = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ) )[id]; diff --git a/src/core/node/secrets.ts b/src/core/node/secrets.ts index 824f139ed..9836fec85 100644 --- a/src/core/node/secrets.ts +++ b/src/core/node/secrets.ts @@ -2,11 +2,7 @@ import { config } from 'dotenv'; config(); -export const SECRET_KEYS = [ - 'DISCORD_TOKEN', - 'WARGAMING_APPLICATION_ID', - 'GH_TOKEN', -] as const; +export const SECRET_KEYS = ['DISCORD_TOKEN', 'GH_TOKEN'] as const; export type SECRET = typeof SECRET_KEYS extends readonly (infer T)[] ? T diff --git a/src/renderers/evolution.tsx b/src/renderers/evolution.tsx index dac3c72d1..f75ff057b 100644 --- a/src/renderers/evolution.tsx +++ b/src/renderers/evolution.tsx @@ -9,7 +9,6 @@ import getPlayerHistories from '../core/blitzstars/getPlayerHistories'; import getTankHistories from '../core/blitzstars/getTankHistories'; import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand'; import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { AccountInfo } from '../types/accountInfo'; import { Histories } from '../types/histories'; import { PlayerClanData } from '../types/playerClanData'; @@ -27,7 +26,7 @@ export default async function evolution( if (type === 'player') { const clan = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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; @@ -77,7 +76,7 @@ export default async function evolution( const minX = Math.min(...xs); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); return ( diff --git a/src/renderers/fullStats.tsx b/src/renderers/fullStats.tsx index 584d97aa9..913f06e31 100644 --- a/src/renderers/fullStats.tsx +++ b/src/renderers/fullStats.tsx @@ -12,7 +12,6 @@ import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats'; import { tankAverages } from '../core/blitzstars/tankAverages'; import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand'; import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { AccountInfo, AllStats, @@ -37,7 +36,7 @@ export default async function fullStats( if (type === 'player' || type === 'multi-tank') { const clan = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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; @@ -141,7 +140,7 @@ export default async function fullStats( } const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); return ( diff --git a/src/renderers/stats.tsx b/src/renderers/stats.tsx index d5baddf7c..82cdfe5a0 100644 --- a/src/renderers/stats.tsx +++ b/src/renderers/stats.tsx @@ -12,7 +12,6 @@ import getDiffedTankStats from '../core/blitzstars/getDiffedTankStats'; import { tankAverages } from '../core/blitzstars/tankAverages'; import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand'; import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand'; -import { secrets } from '../core/node/secrets'; import { theme } from '../stitches.config'; import { AccountInfo, @@ -47,7 +46,7 @@ export default async function stats( if (type === 'player' || type === 'multi-tank') { const clan = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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; @@ -136,7 +135,7 @@ export default async function stats( } const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const overview = ( diff --git a/src/renderers/today.tsx b/src/renderers/today.tsx index 21a68fe75..4b8c386cd 100644 --- a/src/renderers/today.tsx +++ b/src/renderers/today.tsx @@ -14,7 +14,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 { secrets } from '../core/node/secrets'; import { AccountInfo, AllStats } from '../types/accountInfo'; import { PlayerClanData } from '../types/playerClanData'; import { PossiblyPromise } from '../types/possiblyPromise'; @@ -33,10 +32,10 @@ export default async function today( getPeriodNow(), ); const accountInfo = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${secrets.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( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${secrets.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 careerStats: Record = showTotal diff --git a/src/types/tanksStats.ts b/src/types/tanksStats.ts index c86af0d94..2dd30ec5f 100644 --- a/src/types/tanksStats.ts +++ b/src/types/tanksStats.ts @@ -21,3 +21,35 @@ export interface TankStats { export interface NormalizedTankStats { [tankId: number]: IndividualTankStats; } + +export const emptyIndividualTankStats: IndividualTankStats = { + all: { + battles: 0, + capture_points: 0, + damage_dealt: 0, + damage_received: 0, + dropped_capture_points: 0, + frags: 0, + frags8p: 0, + hits: 0, + losses: 0, + max_frags: 0, + max_xp: 0, + shots: 0, + spotted: 0, + survived_battles: 0, + xp: 0, + win_and_survived: 0, + wins: 0, + }, + last_battle_time: 0, + account_id: 0, + max_xp: 0, + in_garage_updated: 0, + max_frags: 0, + frags: 0, + battle_life_time: 0, + in_garage: 0, + tank_id: 0, + mark_of_mastery: 0, +};