From f3e4f8953c070c0cdfec493d072e6a22e3555895 Mon Sep 17 00:00:00 2001 From: JustEvil <71156616+EvilG-MC@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:25:01 -0600 Subject: [PATCH] Fix: emit shoukaku type. (#181) --- .gitignore | 1 + src/Shoukaku.ts | 37 +++++++++++++++---------------------- src/guild/Player.ts | 38 ++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 2f0becee..7f83c41a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ node_modules/ dist/ package-lock.json +pnpm-lock.yaml yarn.lock yarn-debug.log* yarn-error.log* diff --git a/src/Shoukaku.ts b/src/Shoukaku.ts index c713af4d..7e0dd16f 100644 --- a/src/Shoukaku.ts +++ b/src/Shoukaku.ts @@ -96,56 +96,49 @@ export interface VoiceChannelOptions { mute?: boolean; } -export declare interface Shoukaku { +export interface ShoukakuEvents { /** * Emitted when reconnect tries are occurring and how many tries are left * @eventProperty */ - on(event: 'reconnecting', listener: (name: string, reconnectsLeft: number, reconnectInterval: number) => void): this; + 'reconnecting': [name: string, reconnectsLeft: number, reconnectInterval: number]; /** * Emitted when data useful for debugging is produced * @eventProperty */ - on(event: 'debug', listener: (name: string, info: string) => void): this; + 'debug': [name: string, info: string]; /** * Emitted when an error occurs * @eventProperty */ - on(event: 'error', listener: (name: string, error: Error) => void): this; + 'error': [name: string, error: Error]; /** * Emitted when Shoukaku is ready to receive operations * @eventProperty */ - on(event: 'ready', listener: (name: string, reconnected: boolean) => void): this; + 'ready': [name: string, reconnected: boolean]; /** * Emitted when a websocket connection to Lavalink closes * @eventProperty */ - on(event: 'close', listener: (name: string, code: number, reason: string) => void): this; + 'close': [name: string, code: number, reason: string]; /** * Emitted when a websocket connection to Lavalink disconnects * @eventProperty */ - on(event: 'disconnect', listener: (name: string, count: number) => void): this; + 'disconnect': [name: string, count: number]; /** * Emitted when a raw message is received from Lavalink * @eventProperty */ - on(event: 'raw', listener: (name: string, json: unknown) => void): this; - once(event: 'reconnecting', listener: (name: string, reconnectsLeft: number, reconnectInterval: number) => void): this; - once(event: 'debug', listener: (name: string, info: string) => void): this; - once(event: 'error', listener: (name: string, error: Error) => void): this; - once(event: 'ready', listener: (name: string, reconnected: boolean) => void): this; - once(event: 'close', listener: (name: string, code: number, reason: string) => void): this; - once(event: 'disconnect', listener: (name: string, count: number) => void): this; - once(event: 'raw', listener: (name: string, json: unknown) => void): this; - off(event: 'reconnecting', listener: (name: string, reconnectsLeft: number, reconnectInterval: number) => void): this; - off(event: 'debug', listener: (name: string, info: string) => void): this; - off(event: 'error', listener: (name: string, error: Error) => void): this; - off(event: 'ready', listener: (name: string, reconnected: boolean) => void): this; - off(event: 'close', listener: (name: string, code: number, reason: string) => void): this; - off(event: 'disconnect', listener: (name: string, count: number) => void): this; - off(event: 'raw', listener: (name: string, json: unknown) => void): this; + 'raw': [name: string, json: unknown]; +} + +export declare interface Shoukaku { + on(event: K, listener: (...args: ShoukakuEvents[K]) => void): this; + once(event: K, listener: (...args: ShoukakuEvents[K]) => void): this; + off(event: K, listener: (...args: ShoukakuEvents[K]) => void): this; + emit(event: string | symbol, ...args: any[]): boolean; } /** diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 574d0022..75c4d42e 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -122,58 +122,52 @@ export interface FilterOptions { lowPass?: LowPassSettings|null; } -export declare interface Player { +export interface PlayerEvents { /** * Emitted when the current playing track ends * @eventProperty */ - on(event: 'end', listener: (reason: TrackEndEvent) => void): this; + 'end': [reason: TrackEndEvent]; /** * Emitted when the current playing track gets stuck due to an error * @eventProperty */ - on(event: 'stuck', listener: (data: TrackStuckEvent) => void): this; + 'stuck': [data: TrackStuckEvent]; /** * Emitted when the current websocket connection is closed * @eventProperty */ - on(event: 'closed', listener: (reason: WebSocketClosedEvent) => void): this; + 'closed': [reason: WebSocketClosedEvent]; /** * Emitted when a new track starts * @eventProperty */ - on(event: 'start', listener: (data: TrackStartEvent) => void): this; + 'start': [data: TrackStartEvent]; /** * Emitted when there is an error caused by the current playing track * @eventProperty */ - on(event: 'exception', listener: (reason: TrackExceptionEvent) => void): this; + 'exception': [reason: TrackExceptionEvent]; /** * Emitted when the library manages to resume the player * @eventProperty */ - on(event: 'resumed', listener: (player: Player) => void): this; + 'resumed': [player: Player]; /** * Emitted when a playerUpdate even is received from Lavalink * @eventProperty */ - on(event: 'update', listener: (data: PlayerUpdate) => void): this; - once(event: 'end', listener: (reason: TrackEndEvent) => void): this; - once(event: 'stuck', listener: (data: TrackStuckEvent) => void): this; - once(event: 'closed', listener: (reason: WebSocketClosedEvent) => void): this; - once(event: 'start', listener: (data: TrackStartEvent) => void): this; - once(event: 'exception', listener: (reason: TrackExceptionEvent) => void): this; - once(event: 'resumed', listener: (player: Player) => void): this; - once(event: 'update', listener: (data: PlayerUpdate) => void): this; - off(event: 'end', listener: (reason: TrackEndEvent) => void): this; - off(event: 'stuck', listener: (data: TrackStuckEvent) => void): this; - off(event: 'closed', listener: (reason: WebSocketClosedEvent) => void): this; - off(event: 'start', listener: (data: TrackStartEvent) => void): this; - off(event: 'exception', listener: (reason: TrackExceptionEvent) => void): this; - off(event: 'resumed', listener: (player: Player) => void): this; - off(event: 'update', listener: (data: PlayerUpdate) => void): this; + 'update': [data: PlayerUpdate]; } +export declare interface Player { + on(event: K, listener: (...args: PlayerEvents[K]) => void): this; + once(event: K, listener: (...args: PlayerEvents[K]) => void): this; + off(event: K, listener: (...args: PlayerEvents[K]) => void): this; + emit(event: string | symbol, ...args: unknown[]): boolean; +} + + /** * Wrapper object around Lavalink */