Skip to content

Commit

Permalink
Update Vulkava event listeners typings (#26)
Browse files Browse the repository at this point in the history
* Add bun.lockb to .gitignore

* Update Vulkava event listeners typings

* Ignore eslint error

---------

Co-authored-by: David Amorim <davidfilipeamorim@gmail.com>
  • Loading branch information
5antos and davidffa authored Oct 21, 2024
1 parent 61e1235 commit 0c8fd1e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ typings

yarn.lock
package-lock.json
bun.lockb

coverage
coverage
96 changes: 72 additions & 24 deletions lib/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,77 @@ export type VulkavaOptions = {
};

/** Vulkava events */
export type EventListeners<T> = {
(event: 'debug', listener: (message: string) => void): T;
(event: 'raw', listener: (node: Node, payload: unknown) => void): T;
(event: 'nodeConnect', listener: (node: Node) => void): T;
(event: 'nodeResume', listener: (node: Node) => void): T;
(event: 'nodeDisconnect', listener: (node: Node, code: number, reason: string) => void): T;
(event: 'warn', listener: (node: Node, warn: string) => void): T;
(event: 'error', listener: (node: Node, error: Error) => void): T;
(event: 'trackStart', listener: (player: Player, track: Track) => void): T;
(event: 'trackEnd', listener: (player: Player, track: Track, reason: TrackEndReason) => void): T;
(event: 'trackStuck', listener: (player: Player, track: Track, thresholdMs: number) => void): T;
(event: 'trackException', listener: (player: Player, track: Track | UnresolvedTrack, exception: LoadException & { cause: string }) => void): T;
(event: 'playerCreate', listener: (player: Player) => void): T;
(event: 'playerDestroy', listener: (player: Player) => void): T;
(event: 'playerDisconnect', listener: (player: Player, code: number, reason: string) => void): T;
(event: 'queueEnd', listener: (player: Player) => void): T;
(event: 'pong', listener: (node: Node, ping?: number) => void): T;
(event: 'recordFinished', listener: (node: Node, guildId: string, id: string) => void): T;

// Speaking Events (only work on my lavalink (/~https://github.com/davidffa/lavalink/releases) and while recording audio )
(event: 'speakingStart', listener: (player: Player, userId: string) => void): T;
(event: 'speakingStop', listener: (player: Player, userId: string) => void): T;
(event: 'userDisconnect', listener: (player: Player, userId: string) => void): T;
export interface VulkavaEvents {
debug: [message: string];
raw: [
node: Node,
payload: unknown,
];
nodeConnect: [node: Node];
nodeResume: [node: Node];
nodeDisconnect: [
node: Node,
code: number,
reason: string,
];
warn: [
node: Node,
warn: string,
];
error: [
node: Node,
error: Error,
];
trackStart: [
player: Player,
track: Track,
];
trackEnd: [
player: Player,
track: Track,
reason: TrackEndReason,
];
trackStuck: [
player: Player,
track: Track,
thresholdMs: number,
];
trackException: [
player: Player,
track: Track | UnresolvedTrack,
exception: LoadException & { cause: string },
];
playerCreate: [player: Player];
playerDestroy: [player: Player];
playerDisconnect: [
player: Player,
code: number,
reason: string,
];
queueEnd: [player: Player];
pong: [
node: Node,
ping?: number,
];
recordFinished: [
node: Node,
guildId: string,
id: string,
];

// Speaking Events (only work on my lavalink (/~https://github.com/davidffa/lavalink/releases) and while recording audio)
speakingStart: [
player: Player,
userId: string,
];
speakingStop: [
player: Player,
userId: string,
];
userDisconnect: [
player: Player,
userId: string,
];
}

// Search sources (the last two only works on my lavalink (/~https://github.com/davidffa/lavalink/releases) )
Expand Down Expand Up @@ -486,4 +534,4 @@ export type FilterOptions = {

[key: string]: unknown;
}
// ---------- End of Filter typings ----------
// ---------- End of Filter typings ----------
8 changes: 4 additions & 4 deletions lib/Vulkava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Spotify from './sources/Spotify';
import type {
IncomingDiscordPayload,
OutgoingDiscordPayload,
EventListeners,
VulkavaEvents,
PlayerOptions,
SearchResult,
SEARCH_SOURCE,
Expand All @@ -23,8 +23,8 @@ import type {

// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export interface Vulkava {
once: EventListeners<this>;
on: EventListeners<this>;
on<Event extends keyof VulkavaEvents>(event: Event, listener: (...args: VulkavaEvents[Event]) => void): this;
once<Event extends keyof VulkavaEvents>(event: Event, listener: (...args: VulkavaEvents[Event]) => void): this;
}

/**
Expand Down Expand Up @@ -359,4 +359,4 @@ export class Vulkava extends EventEmitter {
}
}
}
}
}

0 comments on commit 0c8fd1e

Please sign in to comment.