mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: use regional season info instead of hard-coded NA
This commit is contained in:
1 parent
9e4094f3a9
commit
ffebe6c696
2 files changed
+26
-14
No files matched your search
+14
-14
@@ -7,6 +7,7 @@ import * as Leaderboard from '../components/Leaderboard';
|
|||||||
import TitleBar from '../components/TitleBar';
|
import TitleBar from '../components/TitleBar';
|
||||||
import Wrapper from '../components/Wrapper';
|
import Wrapper from '../components/Wrapper';
|
||||||
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
import { REGION_NAMES_SHORT, Region } from '../constants/regions';
|
||||||
|
import getRatingsInfo from '../core/blitz/getRatingsInfo';
|
||||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||||
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
import regionToRegionSubdomain from '../core/blitz/regionToRegionSubdomain';
|
||||||
import getMidnightLeaderboard from '../core/database/getMidnightLeaderboard';
|
import getMidnightLeaderboard from '../core/database/getMidnightLeaderboard';
|
||||||
@@ -103,14 +104,10 @@ export interface RatingsNeighbors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Caching ratings info...');
|
console.log('Caching ratings info...');
|
||||||
const ratingsInfo = fetch(
|
const ratingsInfo = getRatingsInfo('com').then((info) => {
|
||||||
'https://na.wotblitz.com/en/api/rating-leaderboards/season/',
|
console.log('Cached ratings info');
|
||||||
)
|
return info;
|
||||||
.then((response) => response.json() as Promise<RatingsInfo>)
|
});
|
||||||
.then((info) => {
|
|
||||||
console.log('Cached ratings info');
|
|
||||||
return info;
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
||||||
async (resolve) => {
|
async (resolve) => {
|
||||||
@@ -182,28 +179,30 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
let players: RatingsPlayer[];
|
let players: RatingsPlayer[];
|
||||||
let midnightLeaderboard: BlitzkriegRatingsLeaderboard | undefined;
|
let midnightLeaderboard: BlitzkriegRatingsLeaderboard | undefined;
|
||||||
let playerId: number | undefined;
|
let playerId: number | undefined;
|
||||||
|
let regionRatingsInfo: RatingsInfo;
|
||||||
|
|
||||||
if (subcommand === 'league') {
|
if (subcommand === 'league') {
|
||||||
const leagueIndex = parseInt(
|
const leagueIndex = parseInt(
|
||||||
interaction.options.getString('league')!,
|
interaction.options.getString('league')!,
|
||||||
);
|
);
|
||||||
const region = interaction.options.getString('region') as Region;
|
const region = interaction.options.getString('region') as Region;
|
||||||
|
regionRatingsInfo = await getRatingsInfo(region);
|
||||||
const regionSubdomain = regionToRegionSubdomain(region);
|
const regionSubdomain = regionToRegionSubdomain(region);
|
||||||
const result = await fetch(
|
const result = await fetch(
|
||||||
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
`https://${regionSubdomain}.wotblitz.com/en/api/rating-leaderboards/league/${leagueIndex}/top/`,
|
||||||
)
|
)
|
||||||
.then((response) => response.json() as Promise<LeagueTop>)
|
.then((response) => response.json() as Promise<LeagueTop>)
|
||||||
.then(({ result }) => result.slice(0, limit));
|
.then(({ result }) => result.slice(0, limit));
|
||||||
const leagueInfo = awaitedRatingsInfo.leagues[leagueIndex];
|
const leagueInfo = regionRatingsInfo.leagues[leagueIndex];
|
||||||
midnightLeaderboard = await getMidnightLeaderboard(
|
midnightLeaderboard = await getMidnightLeaderboard(
|
||||||
region,
|
region,
|
||||||
awaitedRatingsInfo.current_season,
|
regionRatingsInfo.current_season,
|
||||||
);
|
);
|
||||||
|
|
||||||
players = result;
|
players = result;
|
||||||
playersBefore = result[0].number - 1;
|
playersBefore = result[0].number - 1;
|
||||||
playersAfter =
|
playersAfter =
|
||||||
awaitedRatingsInfo.count - result[result.length - 1].number;
|
regionRatingsInfo.count - result[result.length - 1].number;
|
||||||
titleName = `${leagueInfo.title} - ${REGION_NAMES_SHORT[region]}`;
|
titleName = `${leagueInfo.title} - ${REGION_NAMES_SHORT[region]}`;
|
||||||
titleImage = leagueInfo.big_icon.startsWith('http')
|
titleImage = leagueInfo.big_icon.startsWith('http')
|
||||||
? leagueInfo.big_icon
|
? leagueInfo.big_icon
|
||||||
@@ -211,6 +210,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
titleDescription = `Top ${limit} players`;
|
titleDescription = `Top ${limit} players`;
|
||||||
} else {
|
} else {
|
||||||
const { region, id } = await resolvePlayerFromCommand(interaction);
|
const { region, id } = await resolvePlayerFromCommand(interaction);
|
||||||
|
regionRatingsInfo = await getRatingsInfo(region);
|
||||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||||
`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=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||||
);
|
);
|
||||||
@@ -227,7 +227,7 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
||||||
midnightLeaderboard = await getMidnightLeaderboard(
|
midnightLeaderboard = await getMidnightLeaderboard(
|
||||||
region,
|
region,
|
||||||
awaitedRatingsInfo.current_season,
|
regionRatingsInfo.current_season,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (clan) titleNameDiscriminator = `[${clan.tag}]`;
|
if (clan) titleNameDiscriminator = `[${clan.tag}]`;
|
||||||
@@ -240,12 +240,12 @@ export const ratingsCommand = new Promise<CommandRegistryRaw>(
|
|||||||
titleDescription = 'Ratings neighbours';
|
titleDescription = 'Ratings neighbours';
|
||||||
playersBefore = neighbors[0].number - 1;
|
playersBefore = neighbors[0].number - 1;
|
||||||
playersAfter =
|
playersAfter =
|
||||||
awaitedRatingsInfo.count - neighbors[neighbors.length - 1].number;
|
regionRatingsInfo.count - neighbors[neighbors.length - 1].number;
|
||||||
playerId = id;
|
playerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = players.map((player) => {
|
const items = players.map((player) => {
|
||||||
const reward = awaitedRatingsInfo.rewards.find(
|
const reward = regionRatingsInfo.rewards.find(
|
||||||
(reward) =>
|
(reward) =>
|
||||||
player.number >= reward.from_position &&
|
player.number >= reward.from_position &&
|
||||||
player.number <= reward.to_position,
|
player.number <= reward.to_position,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { RatingsInfo } from '../../commands/ratings';
|
||||||
|
import { Region } from '../../constants/regions';
|
||||||
|
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||||
|
|
||||||
|
export default async function getRatingsInfo(region: Region) {
|
||||||
|
const response = await fetch(
|
||||||
|
`https://${regionToRegionSubdomain(
|
||||||
|
region,
|
||||||
|
)}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||||
|
);
|
||||||
|
return (await response.json()) as Promise<RatingsInfo>;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user