Skip to content

Commit

Permalink
fix(Player): handle emitted errors by default
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Nov 28, 2021
1 parent 77d2eee commit 3185557
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Player extends EventEmitter<PlayerEvents> {
public readonly queues = new Collection<Snowflake, Queue>();
public readonly voiceUtils = new VoiceUtils();
public readonly extractors = new Collection<string, ExtractorModel>();
public requiredEvents = ["error", "connectionError"] as string[];

/**
* Creates new Discord Player
Expand Down Expand Up @@ -552,12 +553,25 @@ class Player extends EventEmitter<PlayerEvents> {
scanDeps() {
const line = "-".repeat(50);
const depsReport = generateDependencyReport();
const extractorReport = this.extractors.map((m) => {
return `${m.name} :: ${m.version || "0.1.0"}`;
}).join("\n");
const extractorReport = this.extractors
.map((m) => {
return `${m.name} :: ${m.version || "0.1.0"}`;
})
.join("\n");
return `${depsReport}\n${line}\nLoaded Extractors:\n${extractorReport || "None"}`;
}

emit<U extends keyof PlayerEvents>(eventName: U, ...args: Parameters<PlayerEvents[U]>): boolean {
if (this.requiredEvents.includes(eventName) && !super.eventNames().includes(eventName)) {
// eslint-disable-next-line no-console
console.error(...args);
process.emitWarning(`[DiscordPlayerWarning] Unhandled "${eventName}" event! Events ${this.requiredEvents.map(m => `"${m}"`).join(", ")} must have event listeners!`);
return false;
} else {
return super.emit(eventName, ...args);
}
}

/**
* Resolves queue
* @param {GuildResolvable|Queue} queueLike Queue like object
Expand Down

0 comments on commit 3185557

Please sign in to comment.