Something went wrong. Try again.
TypeScript client for accessing TLE Community.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import Lacuna from '../lacuna';import Endpoint from '../core/endpoint';import type { ServerResponse } from '../core/server';import { ensureTrailingSlash, fixNumbers } from '../core/util';import * as S from '../types/stats';
class Stats extends Endpoint { lacuna: Lacuna; module: string;
constructor(lacuna: Lacuna, module: string) { super(); this.lacuna = lacuna; this.module = module; }
credits(params: S.CreditsParams = {}) { return this.callWithSession<S.CreditsResult>('credits', params); }
empireRank(params: S.EmpireRankParams = {}) { return this.callWithSession<S.EmpireRankResult>('empire_rank', params); }
findEmpireRank(params: S.FindEmpireRankParams) { return this.callWithSession<S.FindEmpireRankResult>('find_empire_rank', params); }
allianceRank(params: S.AllianceRankParams) { return this.callWithSession<S.AllianceRankResult>('alliance_rank', params); }
findAllianceRank(params: S.FindAllianceRankParams) { return this.callWithSession<S.FindAllianceRankResult>('find_alliance_rank', params); }
colonyRank(params: S.ColonyRankParams = {}) { return this.callWithSession<S.ColonyRankResult>('colony_rank', params); }
spyRank(params: S.SpyRankParams = {}) { return this.callWithSession<S.SpyRankResult>('spy_rank', params); }
weeklyMedalWinners(params: S.WeeklyMedalWinnersParams = {}) { return this.callWithSession<S.WeeklyMedalWinnersResult>('weekly_medal_winners', params); }
/** * The in-game "Server" / "General" stats. This is served as a static * `server_overview.json` from the server root, *not* as a JSON-RPC method, so * it takes no params and no session. Resolves to the same * `{ result } | { error }` shape as every other endpoint call. */ async serverOverview(): Promise<ServerResponse<S.ServerOverview>> { // serverUrl can be reassigned after construction, so re-ensure the trailing // slash - without it URL resolution would drop the last path segment. const url = new URL( 'server/server_overview.json', ensureTrailingSlash(this.lacuna.config.serverUrl) ).href; try { const res = await fetch(url); if (!res.ok) { return { error: { code: res.status, message: `server_overview.json responded ${res.status}`, data: {}, }, }; } return { result: fixNumbers(await res.json()) as S.ServerOverview }; } catch (e) { return { error: { code: -1, message: 'Could not fetch server_overview.json', data: { cause: e } }, }; } }}
export default Stats;