erlc.ts
Version:
Clean and typesafe PRC API client for TypeScript
187 lines • 7.86 kB
TypeScript
import { PRCClient } from './client.js';
import { CommandLog, JoinLog, KillLog, ModCall, Player } from './types.js';
/**
* Helper utilities for interacting with the PRCClient and managing player/server data.
* Provides methods for player management, messaging, server stats, and log retrieval.
* All methods handle API errors by propagating them to the caller.
*/
export declare class PRCHelpers {
private client;
/**
* Creates an instance of PRCHelpers.
* @param client - The PRCClient instance to use for API calls.
*/
constructor(client: PRCClient);
/**
* Finds a player by name or ID using partial match (case-insensitive).
* Searches both the player name and the full Player string.
* @param nameOrId - The player's name or ID to search for.
* @returns The found player or null if not found.
*/
findPlayer(nameOrId: string): Promise<Player | null>;
/**
* Retrieves all players on a specific team.
* @param team - The team name to filter by (case-insensitive).
* @returns Array of players on the specified team.
*/
getPlayersByTeam(team: string): Promise<Player[]>;
/**
* Retrieves all staff members (players with non-Normal permission).
* @returns Array of staff players.
*/
getStaff(): Promise<Player[]>;
/**
* Retrieves the current number of online players.
* @returns The number of online players.
*/
getOnlineCount(): Promise<number>;
/**
* Checks if the server is at maximum capacity.
* @returns True if the server is full, false otherwise.
*/
isServerFull(): Promise<boolean>;
/**
* Sends a global message to all players on the server.
* @param message - The message to broadcast.
*/
sendMessage(message: string): Promise<void>;
/**
* Sends a private message to a specific player.
* @param player - The name of the player to message.
* @param message - The content of the private message.
*/
sendPM(player: string, message: string): Promise<void>;
/**
* Kicks a player from the server.
* @param player - The name of the player to kick.
* @param reason - Optional reason for the kick.
*/
kickPlayer(player: string, reason?: string): Promise<void>;
/**
* Bans a player from the server.
* @param player - The name of the player to ban.
* @param reason - Optional reason for the ban.
*/
banPlayer(player: string, reason?: string): Promise<void>;
/**
* Teleports a player to another player or location.
* @param player - The name of the player to teleport.
* @param target - The target player name or location coordinates.
*/
teleportPlayer(player: string, target: string): Promise<void>;
/**
* Sets a player's team.
* @param player - The name of the player to change teams.
* @param team - The name of the team to assign.
*/
setTeam(player: string, team: string): Promise<void>;
/**
* Retrieves recent join logs within the specified time frame.
* @param minutes - Number of minutes to look back (default: 10).
* @returns Array of join log entries.
*/
getRecentJoins(minutes?: number): Promise<JoinLog[]>;
/**
* Retrieves recent leave logs within the specified time frame.
* @param minutes - Number of minutes to look back (default: 10).
* @returns Array of leave log entries.
*/
getRecentLeaves(minutes?: number): Promise<JoinLog[]>;
/**
* Retrieves kill logs for a specific player within the specified time frame.
* @param player - The name or ID of the player (partial match, case-insensitive).
* @param hours - Number of hours to look back (default: 1).
* @returns Array of kill log entries where the player was the killer.
*/
getPlayerKills(player: string, hours?: number): Promise<KillLog[]>;
/**
* Retrieves death logs for a specific player within the specified time frame.
* @param player - The name or ID of the player (partial match, case-insensitive).
* @param hours - Number of hours to look back (default: 1).
* @returns Array of kill log entries where the player was killed.
*/
getPlayerDeaths(player: string, hours?: number): Promise<KillLog[]>;
/**
* Retrieves command logs for a specific player within the specified time frame.
* @param player - The name or ID of the player (partial match, case-insensitive).
* @param hours - Number of hours to look back (default: 1).
* @returns Array of command log entries for the player.
*/
getPlayerCommands(player: string, hours?: number): Promise<CommandLog[]>;
/**
* Retrieves unanswered mod calls within the specified time frame.
* @param hours - Number of hours to look back (default: 1).
* @returns Array of unanswered mod call entries.
*/
getUnansweredModCalls(hours?: number): Promise<ModCall[]>;
/**
* Waits for a player to appear online, polling at intervals until timeout.
* @param nameOrId - The player's name or ID to wait for (partial match, case-insensitive).
* @param timeoutMs - Timeout in milliseconds (default: 30000).
* @returns The found player.
* @throws Error if the player is not found within the timeout.
*/
waitForPlayer(nameOrId: string, timeoutMs?: number): Promise<Player>;
/**
* Waits for the server to reach a specific player count, polling at intervals until timeout.
* @param count - The target player count to wait for.
* @param timeoutMs - Timeout in milliseconds (default: 60000).
* @throws Error if the count is not reached within the timeout.
*/
waitForPlayerCount(count: number, timeoutMs?: number): Promise<void>;
/**
* Parses a player string in the format "PlayerName:ID" into an object.
* @param player - The player string to parse.
* @returns An object containing the player's Name and ID.
* @throws Error if the player string is not in the expected format.
*/
formatPlayer(player: string): {
Name: string;
ID: string;
};
/**
* Formats a UNIX timestamp into a localized date/time string.
* @param timestamp - The UNIX timestamp in seconds.
* @returns The formatted date/time string.
*/
formatTimestamp(timestamp: number): string;
/**
* Formats the uptime from a start timestamp to the current time as hours and minutes.
* @param startTimestamp - The server start timestamp in seconds.
* @returns The formatted uptime string (e.g., "2h 30m").
*/
formatUptime(startTimestamp: number): string;
/**
* Kicks all players from a specific team.
* @param team - The team name to kick players from (case-insensitive).
* @param reason - Optional reason for kicking.
* @returns Array of player names that were kicked.
*/
kickAllFromTeam(team: string, reason?: string): Promise<string[]>;
/**
* Sends a private message to all staff members.
* @param message - The message to send to staff.
*/
messageAllStaff(message: string): Promise<void>;
/**
* Retrieves comprehensive server statistics for the specified time period.
* @param hours - Number of hours to look back for recent stats (default: 24).
* @returns An object containing current server info and recent activity stats.
*/
getServerStats(hours?: number): Promise<{
current: {
players: number;
maxPlayers: number;
name: string;
owner: number;
};
recent: {
joins: number;
kills: number;
commands: number;
modCalls: number;
uniquePlayers: number;
};
}>;
}
//# sourceMappingURL=helpers.d.ts.map