mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: added ratings leaderboard generation and publication
This commit is contained in:
1 parent
098e6c09b9
commit
6d9e6973d5
35 files changed
+412
-84
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { serverAndIdPattern } from '../discord/resolvePlayerFromCommand';
|
||||
import throwError from '../node/throwError';
|
||||
import listClans from './listClans';
|
||||
@@ -6,7 +6,7 @@ import listClans from './listClans';
|
||||
export default async function getBlitzClan(clan: string) {
|
||||
if (serverAndIdPattern.test(clan)) {
|
||||
const [server, accountId] = clan.split('/');
|
||||
return { server: server as BlitzServer, id: Number(accountId) };
|
||||
return { server: server as RegionDomain, id: Number(accountId) };
|
||||
} else {
|
||||
const accounts = await listClans(clan);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers';
|
||||
import { REGION_DOMAIN_NAMES, RegionDomain } from '../../constants/regions';
|
||||
import { TanksStats } from '../../types/tanksStats';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/arguments';
|
||||
import throwError from '../node/throwError';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
|
||||
export default async function getTankStats(server: BlitzServer, id: number) {
|
||||
export default async function getTankStats(server: RegionDomain, id: number) {
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
@@ -12,7 +12,7 @@ export default async function getTankStats(server: BlitzServer, id: number) {
|
||||
if (tankStats[id] === null) {
|
||||
throw throwError(
|
||||
'No tank stats available',
|
||||
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${BLITZ_SERVERS[server]} server.`,
|
||||
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${REGION_DOMAIN_NAMES[server]} server.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { Clan, ClanList } from '../../types/clanList';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/arguments';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
@@ -21,7 +21,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'com' as BlitzServer,
|
||||
server: 'com' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<ClanList>(
|
||||
@@ -31,7 +31,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'eu' as BlitzServer,
|
||||
server: 'eu' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<ClanList>(
|
||||
@@ -41,7 +41,7 @@ export default async function listClans(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'asia' as BlitzServer,
|
||||
server: 'asia' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
])
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { Account, AccountList } from '../../types/accountList';
|
||||
import { WARGAMING_APPLICATION_ID } from '../node/arguments';
|
||||
import getWargamingResponse from './getWargamingResponse';
|
||||
@@ -25,7 +25,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'com' as BlitzServer,
|
||||
server: 'com' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<AccountList>(
|
||||
@@ -35,7 +35,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'eu' as BlitzServer,
|
||||
server: 'eu' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
getWargamingResponse<AccountList>(
|
||||
@@ -45,7 +45,7 @@ export default async function listPlayers(search: string, limit = 9) {
|
||||
value &&
|
||||
value.map((account) => ({
|
||||
...account,
|
||||
server: 'asia' as BlitzServer,
|
||||
server: 'asia' as RegionDomain,
|
||||
})),
|
||||
),
|
||||
])
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { AllStats } from '../../types/accountInfo';
|
||||
import getTankHistories, {
|
||||
TankHistories,
|
||||
@@ -35,7 +35,7 @@ export const emptyTankHistoryNode: TankHistoryRaw = {
|
||||
};
|
||||
|
||||
export default async function getDiffedTankStats(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
id: number,
|
||||
start: number,
|
||||
end: number,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { Period } from '../discord/addPeriodSubCommands';
|
||||
import getTimeDaysAgo from './getTimeDaysAgo';
|
||||
|
||||
export default function getPeriodStart(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
period: Exclude<Period, 'custom'>,
|
||||
) {
|
||||
if (period === 'career') {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { AccountInfo, AllStats } from '../../types/accountInfo';
|
||||
import {
|
||||
GetHistoriesOptions,
|
||||
@@ -25,13 +25,13 @@ export interface PlayerHistoryRaw {
|
||||
account_id: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
region: BlitzServer;
|
||||
region: RegionDomain;
|
||||
}
|
||||
|
||||
export type PlayerHistoriesRaw = PlayerHistoryRaw[];
|
||||
|
||||
export default async function getPlayerHistories(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
id: number,
|
||||
options?: Partial<GetHistoriesOptions>,
|
||||
) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import {
|
||||
GetHistoriesOptions,
|
||||
Histories,
|
||||
@@ -32,7 +32,7 @@ export const getTankHistoriesDefaultOptions: GetTankHistoriesOptions = {
|
||||
};
|
||||
|
||||
export default async function getTankHistories(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
id: number,
|
||||
options?: Partial<GetTankHistoriesOptions>,
|
||||
) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
|
||||
export const TIME_ZONE_MAPPINGS: Record<BlitzServer, number> = {
|
||||
export const TIME_ZONE_MAPPINGS: Record<RegionDomain, number> = {
|
||||
com: -5, // Central North American Time
|
||||
eu: +1, // Central European Time
|
||||
asia: +7, // Central Asia Standard Time
|
||||
};
|
||||
|
||||
export default function getTimeDaysAgo(server: BlitzServer, daysAgo: number) {
|
||||
export default function getTimeDaysAgo(server: RegionDomain, daysAgo: number) {
|
||||
const now = new Date();
|
||||
if (daysAgo === 0) now.getTime() / 1000;
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
import { BLITZ_SERVERS } from '../../constants/servers';
|
||||
import { REGION_DOMAIN_NAMES } from '../../constants/regions';
|
||||
|
||||
export default function addServerChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
{ name: REGION_DOMAIN_NAMES.com, value: 'com' },
|
||||
{ name: REGION_DOMAIN_NAMES.eu, value: 'eu' },
|
||||
{ name: REGION_DOMAIN_NAMES.asia, value: 'asia' },
|
||||
)
|
||||
.setRequired(true);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AutocompleteInteraction,
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { BLITZ_SERVERS } from '../../constants/servers';
|
||||
import { REGION_DOMAIN_NAMES } from '../../constants/regions';
|
||||
import listClans from '../blitz/listClans';
|
||||
|
||||
export default async function autocompleteClan(
|
||||
@@ -18,7 +18,7 @@ export default async function autocompleteClan(
|
||||
? players.map(
|
||||
(player) =>
|
||||
({
|
||||
name: `${player.name} (${BLITZ_SERVERS[player.server]})`,
|
||||
name: `${player.name} (${REGION_DOMAIN_NAMES[player.server]})`,
|
||||
value: `${player.server}/${player.clan_id}`,
|
||||
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
AutocompleteInteraction,
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { BLITZ_SERVERS } from '../../constants/servers';
|
||||
import { REGION_DOMAIN_NAMES } from '../../constants/regions';
|
||||
import listPlayers from '../blitz/listPlayers';
|
||||
|
||||
export default async function autocompleteUsername(
|
||||
@@ -19,7 +19,9 @@ export default async function autocompleteUsername(
|
||||
? players.map(
|
||||
(player) =>
|
||||
({
|
||||
name: `${player.nickname} (${BLITZ_SERVERS[player.server]})`,
|
||||
name: `${player.nickname} (${
|
||||
REGION_DOMAIN_NAMES[player.server]
|
||||
})`,
|
||||
value: `${player.server}/${player.account_id}`,
|
||||
}) satisfies ApplicationCommandOptionChoiceData<string>,
|
||||
)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from '../express/resolvePeriodFromURL';
|
||||
|
||||
export default function resolvePeriodFromButton(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
interaction: ButtonInteraction<CacheType>,
|
||||
) {
|
||||
return resolvePeriodFromURL(server, `${CYCLIC_API}/${interaction.customId}`);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
@@ -31,7 +31,7 @@ export interface ResolvedPeriod {
|
||||
}
|
||||
|
||||
export default function resolvePeriodFromCommand(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
let statsName: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import listPlayers, {
|
||||
usernamePatternWithoutPosition,
|
||||
} from '../blitz/listPlayers';
|
||||
@@ -8,7 +8,7 @@ import throwError from '../node/throwError';
|
||||
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
|
||||
|
||||
export interface ResolvedPlayer {
|
||||
server: BlitzServer;
|
||||
server: RegionDomain;
|
||||
id: number;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export default async function resolvePlayerFromCommand(
|
||||
if (serverAndIdPattern.test(username)) {
|
||||
const [server, accountId] = username.split('/');
|
||||
return {
|
||||
server: server as BlitzServer,
|
||||
server: server as RegionDomain,
|
||||
id: Number(accountId),
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Request } from 'express';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
||||
|
||||
export default function resolvePeriodFromRequest(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
request: Request,
|
||||
) {
|
||||
return resolvePeriodFromURL(server, `${CYCLIC_API}${request.path}`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '../discord/resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromURL(
|
||||
server: BlitzServer,
|
||||
server: RegionDomain,
|
||||
urlString: string,
|
||||
) {
|
||||
let statsName: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BlitzServer } from '../../constants/servers';
|
||||
import { RegionDomain } from '../../constants/regions';
|
||||
import { ResolvedPlayer } from '../discord/resolvePlayerFromCommand';
|
||||
|
||||
export default function resolvePlayerFromURL(urlString: string) {
|
||||
@@ -6,6 +6,6 @@ export default function resolvePlayerFromURL(urlString: string) {
|
||||
|
||||
return {
|
||||
id: parseInt(url.searchParams.get('id')!),
|
||||
server: url.searchParams.get('server') as BlitzServer,
|
||||
server: url.searchParams.get('server') as RegionDomain,
|
||||
} satisfies ResolvedPlayer;
|
||||
}
|
||||
Reference in new issue
Block a user