UNPKG

ddnet

Version:

A typescript npm package for interacting with data from ddnet.org

149 lines (148 loc) 3.98 kB
import { RankAvailableRegion, ServerRegion } from '../../util.js'; import { Map } from '../maps/Map.js'; import { ActivityEntry } from './ActivityEntry.js'; import { Finishes } from './Finishes.js'; import { GlobalLeaderboard } from './GlobalLeaderboard.js'; import { CompletedMapStats, UncompletedMapStats } from './MapStats.js'; import { Partner } from './Partner.js'; import { Servers } from './Servers.js'; /** * Represents a DDNet player. * * @example * ```ts * const coolGuy = await Player.new('Sans3108'); * * console.log(coolGuy.favoriteServer); // "GER" * console.log(coolGuy.globalLeaderboard.completionist.points); // 2727 * ``` */ export declare class Player { #private; /** * Player responses cache. (8h default TTL) */ private static cache; /** * Sets the TTL (Time-To-Live) for objects in cache. */ static setTTL: (ttlMS?: number) => void; /** * Clears the {@link Player.cache}. */ static clearCache: () => Promise<void>; /** * The name of this player. */ name: string; /** * The url of this player on ddnet.org */ url: string; /** * Global leaderboard stats for this player. */ globalLeaderboard: GlobalLeaderboard; /** * Total amount of points earnable from first completions across all maps. */ totalCompletionistPoints: number; /** * The favorite server region of this player. */ favoriteServer: ServerRegion; /** * First and recent finishes for this player. * * @remarks Does not include rank information for any finishes, values are set to `-1`. */ finishes: Finishes; /** * Favorite partners of this player. */ favoritePartners: Partner[]; /** * Server stats leaderboards for this player. */ serverTypes: Servers; /** * Recorded player activity. */ activity: ActivityEntry[]; /** * Number of hours played in the past 365 days by this player. */ hoursPlayedPast365days: number; /** * All maps stats for this player. */ allMapStats: (UncompletedMapStats | CompletedMapStats)[]; /** * Create a new instance of {@link Player} from API data. * Not intended to be used, use {@link new Player.new} instead. */ private constructor(); /** * Fetch, parse and construct a new {@link Player} instance. */ static new( /** * The name or ddnet.org url of this player. */ nameOrUrl: string, /** * Wether to bypass the player data cache. */ bypassCache?: boolean): Promise<Player>; /** * Parse an object using the player {@link _Schema_players_json2 raw data zod schema}. */ private static parseObject; /** * Fetch the player data from the API. */ private static makeRequest; /** * Populate the object with the raw player data. */ private populate; /** * Refresh the data for this player. */ refresh(): Promise<this>; /** * Returns the name and url of this player in markdown format. */ toString(): string; /** * Returns an array of objects containing the names of all finished maps and a function to turn them into proper {@link Map} objects. */ getAllFinishedMapNames( /** * Wether to bypass the cache. */ force?: boolean, /** * The region to pull ranks from in the `toMap` function from the returned value. Omit for global ranks. */ rankSource?: RankAvailableRegion | null): Promise<{ name: string; toMap: () => Promise<Map>; }[]>; /** * Search for a player. */ static search( /** * The value to search for. */ value: string, /** * Wether to bypass the cache. */ force?: boolean): Promise<{ name: string; points: number; toPlayer: () => Promise<Player>; }[] | null>; }