import { PlayerData } from "@skeldjs/core"; import { Room } from "../worker"; import { AccessCheckFn } from "../api"; export interface ChatCommandParameter { variadic: boolean; required: boolean; name: string; } export declare class CommandCallError extends Error { } export declare class ChatCommandContext { /** * The room that this command came from. */ readonly room: Room; /** * The player that sent the message calling the command. */ readonly player: PlayerData; /** * The original message that the player sent (without the leading '/'). */ readonly message: string; constructor( /** * The room that this command came from. */ room: Room, /** * The player that sent the message calling the command. */ player: PlayerData, /** * The original message that the player sent (without the leading '/'). */ message: string); /** * Reply to the message that called this command. * @summary Calls {@link Room.sendChat} * @param message The message to reply with. */ reply(message: string, ...fmt: any): Promise; } export declare type ChatCommandCallback = (ctx: ChatCommandContext, args?: any) => any; export declare class ChatCommandUsage { readonly name: string; readonly params: ChatCommandParameter[]; constructor(name: string, params: ChatCommandParameter[]); /** * Create a formatted usage of this command, in [standard unix command-line * command syntax](https://en.wikipedia.org/wiki/Command-line_interface#Command_description_syntax). */ toString(prefix?: string): string; } export declare class RegisteredChatCommand { readonly usage: ChatCommandUsage; readonly description: string; readonly accessCheck: AccessCheckFn; readonly callback: ChatCommandCallback; constructor(usage: ChatCommandUsage, description: string, accessCheck: AccessCheckFn, callback: ChatCommandCallback); static parseCommandUsageString(usage: string): ChatCommandUsage; static parse(usageString: string, description: string, accessCheck: AccessCheckFn, callback: ChatCommandCallback): RegisteredChatCommand; /** * Verify that an array of arguments correctly fits the usage of this command. * @param args The arguments to verify. * @returns The arguments mapped from parameter name to value of the argument * passed. */ checkArguments(prefix: string, args: string[]): Record | CommandCallError; } export declare class ChatCommandHandler { readonly room: Room; registeredCommands: Map; constructor(room: Room); registerHelpCommand(): void; /** * Register a command into the command handler. * @param usageString How to use the command in [standard unix command-line command * syntax](https://en.wikipedia.org/wiki/Command-line_interface#Command_description_syntax). * @param description A short summary of what the command does, how to use it, etc. * @param accessCheck A function to determine whether a player can view this command. * @param callback A callback function for when the command is called. * @returns The command that was parsed. * @example * ```ts * worker.chatCommandHandler.parseMessage("ping", "Ping the server.", (ctx, args) => { * ctx.reply("pong!"); * }); * ``` */ registerCommand(usageString: string, description: string, accessCheck: AccessCheckFn, callback: ChatCommandCallback): RegisteredChatCommand; /** * Remove a command from the command handler. * @param commandName The name of the command to be removed, should be {@link RegisteredChatCommand.name}. * ```ts * worker.chatCommandHandler.removeCommand("ping"); * ``` */ removeCommand(commandName: string): void; /** * Parse a message calling a command. Does not trim off a leading command prefix. * @param ctx Context for the message. * @param message The message to parse. * @example * ```ts * const message = "setname weakeyes"; * const ctx = new ChatCommandContext(room, room.players.host, message); * * await worker.chatCommandHandler.parseMessage(ctx, message); * ``` */ parseMessage(ctx: ChatCommandContext, message: string): Promise; /** * Get all commands for a player that are available to them and can use. * @param player The player to get available cmomands for. * @returns All commands that {@link player} can use. */ getAvailableCommandsForPlayer(player: PlayerData): RegisteredChatCommand[]; }