reconnectedchat
Version:
Framework for the ReconnectedCC Chatbox v2
195 lines • 8.24 kB
TypeScript
/// <reference types="node" />
import * as events from "events";
import { Capability, FormattingMode, User } from "./types";
import { Success, RequestError } from "./packets";
import { ChatboxChatMessage, ChatboxCommand, DiscordChatMessage, IngameChatMessage, Leave, Join, Death, WorldChange, AFKReturn, AFK, ServerRestartCancelled, ServerRestartScheduled } from "./events";
export declare interface Client {
/**
* Minecraft username of the owner of the chatbox license
*/
owner: string;
/**
* List of capabilities this chatbox license can do. Typically, guest connections can only use `read`. Connections
* with a license will usually have `read`, `command` and `tell`.
*/
capabilities: Capability[];
/**
* List of currently online players
*/
players: User[];
/**
* Endpoint of the Chatbox server. Must include `wss://` and the version route. Defaults to `wss://chat.reconnected.cc/v2/`.
*/
endpoint: string;
/**
* Default name for chatbox messages
*/
defaultName: string | undefined;
/**
* Default formatting mode for say and tell messages.
* Defaults to "markdown"
*/
defaultFormattingMode: FormattingMode;
running: boolean;
/**
* Connect to the Chatbox server
* @param callback Callback to run when the connection is open
*/
connect(callback?: (client?: Client) => void): void;
/**
* Close the connection to the Chatbox server
* @param soft Keep running status as is
*/
close(soft?: boolean): void;
/**
* Close and reconnect to the Chatbox server
* @param wait Whether to wait before reconnecting.
*/
reconnect(wait?: boolean): void;
/**
* Sends a message to the in-game public chat.
*
* @param text The message to send.
* @param name The name of the chatbox to show. If no name is specified, it will default to the username of the
* license owner.
* @param mode The formatting mode to use. You can use these formatting modes:
* - `markdown` - Discord-like [Markdown syntax](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-).
* Supports URLs, but not colours.
* - `format` - Minecraft-like [formatting codes](https://minecraft.wiki/w/Formatting_codes) using
* ampersands (e.g. `&e` for yellow). Supports colours, but not URLs.
* - `minimessage` - HTML-like [tags](https://docs.advntr.dev/minimessage/format.html) (e.g. `<yellow></yellow>` for yellow).
* Supports colours and hover events.
*
* If no mode is specified, it will default to the mode specified in the constructor.
*
* @returns A {@link Success} object containing if the message was sent.
*/
say(text: string | User, name?: string, mode?: FormattingMode): Promise<Success>;
/**
* Sends a private message to an in-game player.
*
* @param user The username or UUID of the user to send the message to.
* @param text The message to send.
* @param name The name of the chatbox to show. If no name is specified, it will default to the username of the
* license owner.
* @param mode The formatting mode to use. You can use these formatting modes:
* - `markdown` - Discord-like [Markdown syntax](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-).
* Supports URLs, but not colours.
* - `format` - Minecraft-like [formatting codes](https://minecraft.wiki/w/Formatting_codes) using
* ampersands (e.g. `&e` for yellow). Supports colours, but not URLs.
* - `minimessage` - HTML-like [tags](https://docs.advntr.dev/minimessage/format.html) (e.g. `<yellow></yellow>` for yellow).
* Supports colours and hover events.
*
* If no mode is specified, it will default to the mode specified in the constructor.
*
* @returns A {@link Success} object containing if the message was sent.
*/
tell(user: string | User, text: string, name?: string, mode?: FormattingMode): Promise<Success>;
/** Emitted when the Chatbox client is ready to send and receive messages. */
on(event: "ready", listener: () => void): this;
on(event: "players", listener: () => void): this;
on(event: "closing", listener: () => void): this;
on(event: "error", listener: () => void): this;
on(event: "raw", listener: (rawData: {
[key: string]: any;
}) => void): this;
on(event: "ws_error", listener: (err: RequestError) => void): this;
/**
* The event received when a player posts a message in public chat. The `read` capability is required to receive
* chat events.
* @event
*/
on(event: "chat_ingame", listener: (message: IngameChatMessage) => void): this;
/**
* The event received when a player posts a message in Discord. The `read` capability is required to receive chat
* events.
* @event
*/
on(event: "chat_discord", listener: (message: DiscordChatMessage) => void): this;
/**
* The event received when another chatbox sends a message. The `read` capability is required to receive chat
* events.
* @event
*/
on(event: "chat_chatbox", listener: (message: ChatboxChatMessage) => void): this;
/**
* The event received when a player runs a chatbox command (public backslash commands: `\command`, private
* owner-only caret/pipe commands: `^command`) in-game. The `command` capability is required to receive command
* events.
* @event
*/
on(event: "command", listener: (command: ChatboxCommand) => void): this;
/**
* The event received when a player joins the game.
* @event
*/
on(event: "join", listener: (join: Join) => void): this;
/**
* The event received when a player leaves the game.
* @event
*/
on(event: "leave", listener: (leave: Leave) => void): this;
/**
* The event received when a player dies in-game.
* @event
*/
on(event: "death", listener: (death: Death) => void): this;
/**
* The event received when a player changes world.
* @event
*/
on(event: "world_change", listener: (worldChange: WorldChange) => void): this;
/**
* The event received when a player goes AFK in-game.
* @event
*/
on(event: "afk", listener: (afk: AFK) => void): this;
/**
* The event received when a player returns from being AFK in-game.
* @event
*/
on(event: "afk_return", listener: (afkReturn: AFKReturn) => void): this;
/**
* The event received when a server restart has been scheduled. At the time of `restartAt`, the server will restart
* and the websocket will be disconnected.
*
* @see https://docs.reconnected.cc/chatbox/websocket.html#server-restart-scheduled-event
* @event
*/
on(event: "server_restart_scheduled", listener: (event: ServerRestartScheduled) => void): this;
/**
* The event received when a previously scheduled server restart has now been cancelled.
*
* @see https://docs.reconnected.cc/chatbox/websocket.html#server-restart-cancelled-event
* @event
*/
on(event: "server_restart_cancelled", listener: (event: ServerRestartCancelled) => void): this;
}
export declare class Client extends events.EventEmitter {
owner: string;
capabilities: Capability[];
players: User[];
endpoint: string;
defaultName: string | undefined;
defaultFormattingMode: FormattingMode;
waitTimeRestart: number;
running: boolean;
private _delay;
private readonly _queue;
private readonly _awaitingQueue;
private _processingQueue;
private _queueCounter;
private readonly _token;
private _ws?;
constructor(token: string, options?: undefined | {
defaultName?: string | undefined;
defaultFormattingMode?: FormattingMode | undefined;
});
private updatePlayer;
private _onReady;
private _onMessage;
private _handleEvent;
private _processQueue;
private _sleep;
}
//# sourceMappingURL=Client.d.ts.map