import { EventEmitter } from 'events'; import { LavalinkNode } from './node'; import { LavalinkPlayer } from './player'; import type { ManagerOptions, ManagerEventMap, NodeOptions, PlayerOptions, SearchResult, DiscordJSClientLike, ErisClientLike, OceanicClientLike } from './types'; /** * Central manager for the devcodes-lavalink client. * * Responsibilities: * - Owns all nodes and players * - Routes Discord voice-state / voice-server-update packets * - Coordinates player persistence save + restore * - Load-balances new players across nodes by penalty score * * @example * ```ts * const manager = new LavalinkManager({ * nodes: [{ host: 'localhost', port: 2333, password: 'youshallnotpass' }], * send: (guildId, payload) => { * client.guilds.cache.get(guildId)?.shard.send(payload); * }, * }); * * client.once('ready', () => manager.init(client.user!.id)); * * // Forward raw gateway packets so the manager can handle voice * client.on('raw', (packet) => manager.handleRawPacket(packet)); * ``` */ export declare class LavalinkManager extends EventEmitter { readonly nodes: Map; readonly players: Map; readonly options: ManagerOptions; /** The bot's Discord user ID — set via `init()` or `ManagerOptions.clientId` */ clientId: string; /** Name reported to Lavalink in the WebSocket handshake */ clientName: string; private readonly _persistence; private readonly _voiceStates; private readonly _voiceServers; private readonly _pendingRestores; constructor(options: ManagerOptions); /** * Connect all nodes. Call this once the Discord client is ready. * @param clientId The bot's Discord user ID (overrides `options.clientId`). */ init(clientId: string): this; /** Add (and optionally connect) a new node at runtime */ addNode(options: NodeOptions): LavalinkNode; /** Disconnect and remove a node */ removeNode(identifier: string): void; /** The connected node with the lowest load-penalty score */ leastLoadNode(): LavalinkNode; /** * Create a player for the given guild, or return the existing one. * The player is NOT connected to voice until you call `player.connect()`. */ create(options: PlayerOptions): LavalinkPlayer; /** Get the player for a guild, or `undefined` if none exists */ get(guildId: string): LavalinkPlayer | undefined; /** Destroy the player for a guild (disconnects voice + clears persistence) */ destroy(guildId: string): Promise; /** * Search for tracks or load a URL. * * @param query URL or search terms. If not a URL, the `defaultSearchPlatform` * prefix is prepended (e.g. `ytsearch:never gonna give you up`). * @param node Override which node handles this request. */ search(query: string, node?: LavalinkNode): Promise; /** * Feed raw Discord gateway packets into the manager. * * Wire this up in your bot with: * ```ts * client.on('raw', (packet) => manager.handleRawPacket(packet)); * ``` * * The manager only acts on `VOICE_STATE_UPDATE` and `VOICE_SERVER_UPDATE`. */ handleRawPacket(packet: { t?: string; d?: unknown; }): void; /** * `lavalink-client` compat alias for `handleRawPacket()`. * Both names are identical in behaviour — use whichever your bot already calls. * * @example * ```ts * // lavalink-client style: * client.on('raw', (d) => manager.sendRawData(d)); * // devcodes-lavalink style: * client.on('raw', (d) => manager.handleRawPacket(d)); * ``` */ sendRawData(packet: { t?: string; d?: unknown; }): void; /** @internal */ _removePlayer(player: LavalinkPlayer): void; /** @internal */ _savePlayer(player: LavalinkPlayer): void; /** * @internal * Called by `LavalinkNode` after a `ready` op with `resumed: false`, * meaning Lavalink was fully restarted and all player state was lost there. * We restore from our own disk-based persistence file. */ _restorePlayers(node: LavalinkNode): Promise; private _restorePlayer; private _handleVoiceStateUpdate; private _handleVoiceServerUpdate; /** * Once we have both voice-session-ID and voice-server data, send the * combined voice update to Lavalink, then handle any pending restore. */ private _checkVoice; private _onShutdown; /** * One-call discord.js wiring — replaces the manual `init` + `raw` setup. * * Automatically: * - Calls `manager.init(client.user.id)` once the client is ready * - Forwards all raw gateway packets to `handleRawPacket()` * * @example * ```ts * const manager = new LavalinkManager({ ... }); * manager.useDiscordJS(client); // ← replaces 4 lines of boilerplate * ``` */ useDiscordJS(client: DiscordJSClientLike): this; /** * One-call Eris wiring — replaces the manual `init` + `rawWS` setup. * * Automatically: * - Calls `manager.init(client.user.id)` once the client is ready * - Forwards all raw `rawWS` packets to `handleRawPacket()` * * @example * ```ts * const manager = new LavalinkManager({ ... }); * manager.useEris(client); // ← replaces 4 lines of boilerplate * ``` */ useEris(client: ErisClientLike): this; /** * One-call Oceanic.js wiring — replaces the manual `init` + `packet` setup. * * Automatically: * - Calls `manager.init(client.user.id)` once the client is ready * - Forwards all raw `packet` events to `handleRawPacket()` * * @example * ```ts * const manager = new LavalinkManager({ ... }); * manager.useOceanic(client); // ← replaces 4 lines of boilerplate * ``` */ useOceanic(client: OceanicClientLike): this; emit(event: K, ...args: ManagerEventMap[K]): boolean; on(event: K, listener: (...args: ManagerEventMap[K]) => void): this; once(event: K, listener: (...args: ManagerEventMap[K]) => void): this; off(event: K, listener: (...args: ManagerEventMap[K]) => void): this; } //# sourceMappingURL=manager.d.ts.map