Skip to content

Commit

Permalink
Better type control + pnpm (#178)
Browse files Browse the repository at this point in the history
lgtm
  • Loading branch information
EvilG-MC authored Jun 18, 2024
1 parent e5ea077 commit 8d77908
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
node_modules/
dist/
package-lock.json
pnpm-lock.yaml
yarn.lock
yarn-debug.log*
yarn-error.log*
Expand Down
36 changes: 14 additions & 22 deletions src/Shoukaku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,56 +96,48 @@ 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<K extends keyof ShoukakuEvents>(event: K, listener: (...args: ShoukakuEvents[K]) => void): this;
once<K extends keyof ShoukakuEvents>(event: K, listener: (...args: ShoukakuEvents[K]) => void): this;
off<K extends keyof ShoukakuEvents>(event: K, listener: (...args: ShoukakuEvents[K]) => void): this;
}

/**
Expand Down
36 changes: 14 additions & 22 deletions src/guild/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,56 +122,48 @@ 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<K extends keyof PlayerEvents>(event: K, listener: (...args: PlayerEvents[K]) => void): this;
once<K extends keyof PlayerEvents>(event: K, listener: (...args: PlayerEvents[K]) => void): this;
off<K extends keyof PlayerEvents>(event: K, listener: (...args: PlayerEvents[K]) => void): this;
}

/**
Expand Down

0 comments on commit 8d77908

Please sign in to comment.