mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: core chunk 4
This commit is contained in:
1 parent
b827f7f730
commit
9bdb14e13a
22 files changed
+46
-31
No files matched your search
@@ -2,11 +2,14 @@ import { go } from 'fuzzysort';
|
||||
import throwError from '../node/throwError';
|
||||
import { TANKS, tankopedia } from './tankopedia';
|
||||
|
||||
export default async function resolveTankId(tank: string) {
|
||||
const number = parseInt(tank);
|
||||
export default async function resolveTankId(tank: string | number) {
|
||||
const number = typeof tank === 'string' ? parseInt(tank) : tank;
|
||||
|
||||
if (Number.isNaN(number)) {
|
||||
const searchResult = go(tank, await TANKS, { keys: ['name'], limit: 1 });
|
||||
const searchResult = go(`${tank}`, await TANKS, {
|
||||
keys: ['name'],
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (searchResult.length === 0) {
|
||||
throw throwError(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
import { range } from 'lodash';
|
||||
import numberToRomanNumeral from '../blitz/numberToRomanNumeral';
|
||||
import numberToRomanNumeral from '../../core/math/numberToRomanNumeral';
|
||||
|
||||
export default function addTierChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { REGION_NAMES } from '../../constants/regions';
|
||||
import listClans from '../blitz/listClans';
|
||||
import searchClansAcrossRegions from '../../core/blitz/searchClansAcrossRegions';
|
||||
|
||||
export default async function autocompleteClan(
|
||||
interaction: AutocompleteInteraction<CacheType>,
|
||||
@@ -12,7 +12,7 @@ export default async function autocompleteClan(
|
||||
const focusedOption = interaction.options.getFocused(true);
|
||||
if (focusedOption.name !== 'clan') return;
|
||||
if (focusedOption.value.length < 2) return interaction.respond([]);
|
||||
const players = await listClans(focusedOption.value);
|
||||
const players = await searchClansAcrossRegions(focusedOption.value);
|
||||
|
||||
await interaction.respond(
|
||||
players
|
||||
|
||||
@@ -4,14 +4,14 @@ import {
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { REGION_NAMES } from '../../constants/regions';
|
||||
import listPlayers from '../blitz/listPlayers';
|
||||
import searchPlayersAcrossRegions from '../../core/blitz/searchPlayersAcrossRegions';
|
||||
|
||||
export default async function autocompleteUsername(
|
||||
interaction: AutocompleteInteraction<CacheType>,
|
||||
) {
|
||||
const focusedOption = interaction.options.getFocused(true);
|
||||
if (focusedOption.name !== 'username') return;
|
||||
const players = await listPlayers(focusedOption.value);
|
||||
const players = await searchPlayersAcrossRegions(focusedOption.value);
|
||||
|
||||
try {
|
||||
await interaction.respond(
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { ChatInputCommandInteraction } from 'discord.js';
|
||||
import { TreeTypeString } from '../../components/Tanks';
|
||||
import { StatFilters } from '../../core/statistics/filterStats';
|
||||
import resolveTankId from '../blitz/resolveTankId';
|
||||
|
||||
export function getFiltersFromCommand(
|
||||
export async function getFiltersFromCommand(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
) {
|
||||
const tankRaw = interaction.options.getString('tank');
|
||||
|
||||
return {
|
||||
nation: interaction.options.getString('nation') ?? undefined,
|
||||
tier: parseInt(interaction.options.getString('tier') ?? '0') || undefined,
|
||||
@@ -13,6 +16,6 @@ export function getFiltersFromCommand(
|
||||
(interaction.options.getString('tree-type') as
|
||||
| TreeTypeString
|
||||
| undefined) ?? undefined,
|
||||
tank: parseInt(interaction.options.getString('tank') ?? '0') || undefined,
|
||||
tank: tankRaw === null ? undefined : await resolveTankId(tankRaw),
|
||||
} satisfies StatFilters;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChatInputCommandInteraction } from 'discord.js';
|
||||
import { Region } from '../../constants/regions';
|
||||
import listClans from '../blitz/listClans';
|
||||
import searchClansAcrossRegions from '../../core/blitz/searchClansAcrossRegions';
|
||||
import throwError from '../node/throwError';
|
||||
import { serverAndIdPattern } from './resolvePlayerFromCommand';
|
||||
|
||||
@@ -13,7 +13,7 @@ export default async function resolveClanFromCommand(
|
||||
const [server, accountId] = clan.split('/');
|
||||
return { region: server as Region, id: Number(accountId) };
|
||||
} else {
|
||||
const accounts = await listClans(clan);
|
||||
const accounts = await searchClansAcrossRegions(clan);
|
||||
|
||||
if (accounts[0]) {
|
||||
return { region: accounts[0].region, id: accounts[0].clan_id };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { Region } from '../../constants/regions';
|
||||
import listPlayers from '../blitz/listPlayers';
|
||||
import searchPlayersAcrossRegions from '../../core/blitz/searchPlayersAcrossRegions';
|
||||
import { getBlitzFromDiscord } from '../cockroackdb/discordBlitz';
|
||||
import throwError from '../node/throwError';
|
||||
|
||||
@@ -26,7 +26,7 @@ export default async function resolvePlayerFromCommand(
|
||||
id: Number(accountId),
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
const accounts = await listPlayers(commandUsername);
|
||||
const accounts = await searchPlayersAcrossRegions(commandUsername);
|
||||
|
||||
if (accounts[0]) {
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { ContextMenu } from '@radix-ui/themes';
|
||||
import { useEffect, useState } from 'react';
|
||||
import getWN8Percentile from '../../../LEGACY_core/blitz/getWN8Percentile';
|
||||
import {
|
||||
TankopediaEntry,
|
||||
tankopedia,
|
||||
@@ -14,6 +13,7 @@ import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicatio
|
||||
import fetchBlitz from '../../../core/blitz/fetchWargaming';
|
||||
import calculateWN8 from '../../../core/statistics/calculateWN8';
|
||||
import { deltaTankStats } from '../../../core/statistics/deltaTankStats';
|
||||
import getWN8Percentile from '../../../core/statistics/getWN8Percentile';
|
||||
import { useSession } from '../../../stores/session';
|
||||
import { IndividualTankStats, TanksStats } from '../../../types/tanksStats';
|
||||
import { CustomColumnDisplay } from '../../tools/session/components/CustomColumn';
|
||||
|
||||
@@ -18,13 +18,13 @@ import {
|
||||
} from '@radix-ui/themes';
|
||||
import { debounce } from 'lodash';
|
||||
import { ChangeEvent, useRef, useState } from 'react';
|
||||
import listPlayers, {
|
||||
AccountListWithServer,
|
||||
} from '../../../LEGACY_core/blitz/listPlayers';
|
||||
import PageWrapper from '../../../components/PageWrapper';
|
||||
import { REGION_NAMES, Region } from '../../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../../constants/wargamingApplicationID';
|
||||
import fetchBlitz from '../../../core/blitz/fetchWargaming';
|
||||
import searchPlayersAcrossRegions, {
|
||||
AccountListWithServer,
|
||||
} from '../../../core/blitz/searchPlayersAcrossRegions';
|
||||
import { useSession } from '../../../stores/session';
|
||||
import { NormalizedTankStats, TanksStats } from '../../../types/tanksStats';
|
||||
import SessionPage from '../../embeds/session/page';
|
||||
@@ -40,7 +40,7 @@ export default function Page() {
|
||||
const handleChange = debounce(
|
||||
async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
if (event.target.value) {
|
||||
setSearchResults(await listPlayers(event.target.value));
|
||||
setSearchResults(await searchPlayersAcrossRegions(event.target.value));
|
||||
} else {
|
||||
setSearchResults(undefined);
|
||||
setShowSearchResults(false);
|
||||
|
||||
@@ -82,7 +82,7 @@ export const fullStatsCommand = new Promise<CommandRegistryRaw>(
|
||||
async handler(interaction) {
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||
const filters = getFiltersFromCommand(interaction);
|
||||
const filters = await getFiltersFromCommand(interaction);
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
...getCustomPeriodParams(interaction),
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
} from 'discord.js';
|
||||
import { BlitzkriegRatingsLeaderboard } from '../../scripts/buildRatingsLeaderboard';
|
||||
import regionToRegionSubdomain from '../LEGACY_core/blitz/regionToRegionSubdomain';
|
||||
import getMidnightLeaderboard, {
|
||||
DATABASE_REPO,
|
||||
} from '../LEGACY_core/database/getMidnightLeaderboard';
|
||||
@@ -23,6 +22,7 @@ import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
||||
import { getAccountInfo } from '../core/blitz/getAccountInfo';
|
||||
import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
||||
import getArchivedRatingsInfo from '../core/blitzkrieg/getArchivedRatingsInfo';
|
||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { AccountList, usernamePattern } from '../LEGACY_core/blitz/listPlayers';
|
||||
import addRegionChoices from '../LEGACY_core/discord/addRegionChoices';
|
||||
import addUsernameChoices from '../LEGACY_core/discord/addUsernameChoices';
|
||||
import embedInfo from '../LEGACY_core/discord/embedInfo';
|
||||
import { REGION_NAMES, Region } from '../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||
import fetchBlitz from '../core/blitz/fetchWargaming';
|
||||
import {
|
||||
AccountList,
|
||||
usernamePattern,
|
||||
} from '../core/blitz/searchPlayersAcrossRegions';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
export const searchPlayersCommand: CommandRegistry = {
|
||||
|
||||
@@ -74,7 +74,7 @@ export const statsCommand = new Promise<CommandRegistryRaw>(async (resolve) => {
|
||||
async handler(interaction) {
|
||||
const player = await resolvePlayerFromCommand(interaction);
|
||||
const period = resolvePeriodFromCommand(player.region, interaction);
|
||||
const filters = getFiltersFromCommand(interaction);
|
||||
const filters = await getFiltersFromCommand(interaction);
|
||||
const path = interactionToURL(interaction, {
|
||||
...player,
|
||||
...getCustomPeriodParams(interaction),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Percentile } from '../../../../constants/percentiles';
|
||||
import getWN8Percentile from '../../../../LEGACY_core/blitz/getWN8Percentile';
|
||||
import getWN8Percentile from '../../../../core/statistics/getWN8Percentile';
|
||||
import { theme } from '../../../../stitches.config';
|
||||
import { PERCENTILE_COLORS } from '../../../PercentileIndicator';
|
||||
import { Glow } from './components/Glow';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AllStats, SupplementaryStats } from '../../core/blitz/getAccountInfo';
|
||||
import getWN8Percentile from '../../LEGACY_core/blitz/getWN8Percentile';
|
||||
import getWN8Percentile from '../../core/statistics/getWN8Percentile';
|
||||
import isNumber from '../../LEGACY_core/node/isNumber';
|
||||
import { Card } from './components/Card';
|
||||
import { Root } from './components/Root';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import regionToRegionSubdomain from '../../LEGACY_core/blitz/regionToRegionSubdomain';
|
||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||
|
||||
export default async function getRatingsInfo(region: Region) {
|
||||
const response = await fetch(
|
||||
|
||||
File renamed without changes.
@@ -1,13 +1,16 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import fetchBlitz from '../../core/blitz/fetchWargaming';
|
||||
import { Clan, ClanList } from '../../types/clanList';
|
||||
import fetchBlitz from './fetchWargaming';
|
||||
|
||||
export type ClanListWithRegion = (Clan & {
|
||||
region: 'com' | 'eu' | 'asia';
|
||||
})[];
|
||||
|
||||
export default async function listClans(search: string, limit = 9) {
|
||||
export default async function searchClansAcrossRegions(
|
||||
search: string,
|
||||
limit = 9,
|
||||
) {
|
||||
const trimmed = search.trim();
|
||||
if (trimmed.length < 3 && trimmed.length > 100) return [];
|
||||
const normalizedLimit = Math.round(limit / 3);
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import fetchBlitz from '../../core/blitz/fetchWargaming';
|
||||
import fetchBlitz from './fetchWargaming';
|
||||
|
||||
interface Account {
|
||||
nickname: string;
|
||||
@@ -14,7 +14,10 @@ export type AccountListWithServer = (Account & {
|
||||
export const usernamePattern = /^[a-zA-Z0-9_]{3,24}$/;
|
||||
export const usernamePatternWithoutPosition = /[a-zA-Z0-9_]{3,24}/;
|
||||
|
||||
export default async function listPlayers(search: string, limit = 9) {
|
||||
export default async function searchPlayersAcrossRegions(
|
||||
search: string,
|
||||
limit = 9,
|
||||
) {
|
||||
const trimmedSearch = search.trim();
|
||||
const normalizedLimit = Math.round(limit / 3);
|
||||
const encodedSearch = encodeURIComponent(trimmedSearch);
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,3 @@
|
||||
import getWN8Percentile from '../LEGACY_core/blitz/getWN8Percentile';
|
||||
import resolveTankName from '../LEGACY_core/blitz/resolveTankName';
|
||||
import sumStats from '../LEGACY_core/blitz/sumStats';
|
||||
import { tankopedia } from '../LEGACY_core/blitz/tankopedia';
|
||||
@@ -16,6 +15,7 @@ import { getClanAccountInfo } from '../core/blitz/getClanAccountInfo';
|
||||
import getTankStats from '../core/blitz/getTankStats';
|
||||
import getTreeType from '../core/blitz/getTreeType';
|
||||
import calculateWN8 from '../core/statistics/calculateWN8';
|
||||
import getWN8Percentile from '../core/statistics/getWN8Percentile';
|
||||
import { PossiblyPromise } from '../types/possiblyPromise';
|
||||
|
||||
export default async function today(
|
||||
|
||||
Reference in new issue
Block a user