Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
achiragaming committed Mar 4, 2024
1 parent a13d36d commit 9f06213
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
16 changes: 16 additions & 0 deletions examples/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ const client = new Client({ intents: [Guilds, GuildVoiceStates, GuildMessages, M

const damonjs = new DamonJs(
{
resolveError: {
max: 5,
time: 30 * 1000,
},
exceptions: {
max: 5,
time: 30 * 1000,
},
stuck: {
max: 5,
time: 30 * 1000,
},
skipResolveError: true,
skipOnException: true,
skipOnStuck: true,
defaultSearchEngine: 'youtube',

plugins: [new Plugins.PlayerMoved(client)],
},
new Shoukaku(new Connectors.DiscordJS(client), Nodes, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "damonjs",
"version": "1.7.6",
"version": "1.7.7",
"preview": false,
"description": "A modified Shoukaku wrapper with enhanced queue support.",
"main": "dist/Index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './DamonJs';
export { DamonJsTrack, DamonJsQueue, DamonJsPlayer, Plugins };
export * from './Modules/Interfaces';

export const version = '1.7.6';
export const version = '1.7.7';
43 changes: 15 additions & 28 deletions src/Managers/DamonJsPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,14 @@ export class DamonJsPlayer {
const exceptionArr = this.errors.exceptions;
const maxTime = this.damonjs.DamonJsOptions.exceptions.time;
const exceptions = exceptionArr.filter((time: number) => nowTime - time < maxTime);
if (exceptions.length > this.damonjs.DamonJsOptions.exceptions.max) return;
else {
if (!(exceptions.length >= this.damonjs.DamonJsOptions.exceptions.max)) {
this.emit(Events.PlayerException, this, data);
exceptions.push(nowTime);
this.errors.exceptions = exceptions;
if (this.damonjs.DamonJsOptions.skipOnException) {
await this.skip().catch(() => null);
}
}

if (this.damonjs.DamonJsOptions.skipOnException) {
await this.skip().catch(() => null);
}
this.emit(Events.PlayerException, this, data);
return this;
}

private async handleTrackStuck(data: TrackStuckEvent) {
Expand All @@ -155,35 +152,28 @@ export class DamonJsPlayer {
const stuckErr = this.errors.stuck;
const maxTime = this.damonjs.DamonJsOptions.stuck.time;
const stucks = stuckErr.filter((time: number) => nowTime - time < maxTime);
if (stucks.length > this.damonjs.DamonJsOptions.stuck.max) return;
else {
if (!(stucks.length >= this.damonjs.DamonJsOptions.stuck.max)) {
this.emit(Events.PlayerStuck, this, data);
stucks.push(nowTime);
this.errors.stuck = stucks;
if (this.damonjs.DamonJsOptions.skipOnStuck) {
await this.skip().catch(() => null);
}
}

if (this.damonjs.DamonJsOptions.skipOnStuck) {
await this.skip().catch(() => null);
}
this.emit(Events.PlayerStuck, this, data);
return this;
}
private async handleResolveError(current: DamonJsTrack, resolveResult: Error) {
const nowTime = Date.now();
const resolveErr = this.errors.resolveError;
const maxTime = this.damonjs.DamonJsOptions.resolveError.time;
const rErrors = resolveErr.filter((time: number) => nowTime - time < maxTime);
if (rErrors.length > this.damonjs.DamonJsOptions.resolveError.max) return;
else {
if (!(rErrors.length >= this.damonjs.DamonJsOptions.resolveError.max)) {
this.emit(Events.PlayerResolveError, this, current, resolveResult.message);
rErrors.push(nowTime);
this.errors.resolveError = rErrors;
if (this.damonjs.DamonJsOptions.skipResolveError) {
await this.skip().catch(() => null);
}
}

if (this.damonjs.DamonJsOptions.skipResolveError) {
await this.skip().catch(() => null);
}

this.emit(Events.PlayerResolveError, this, current, resolveResult.message);
return this;
}

private async handlePlayerEmpty() {
Expand Down Expand Up @@ -320,12 +310,9 @@ export class DamonJsPlayer {
}
const current = this.queue.current;
current.setDamonJs(this.damonjs);

const resolveResult = await current.resolve({ player: this }).catch((e: Error) => e);

if (resolveResult instanceof Error) {
await this.handleResolveError(current, resolveResult);

throw new DamonJsError(1, `Player ${this.guildId} resolve error: ${resolveResult.message}`);
}
const playOptions = { track: current.encoded, options: {} };
Expand Down
4 changes: 2 additions & 2 deletions src/Managers/Supports/DamonJsTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ export class DamonJsTrack {

const result =
(await this.getTrack(
options.player ?? null,
options.player,
(SourceIDs as any)[this.damonjs.DamonJsOptions.defaultSearchEngine || 'youtube'] || 'yt',
).catch(() => null)) || (await this.getTrack(options.player ?? null, 'youtube').catch(() => null));
).catch(() => null)) || (await this.getTrack(options.player, 'youtube').catch(() => null));
if (!result) throw new DamonJsError(2, 'No results found');

this.encoded = result.encoded;
Expand Down

0 comments on commit 9f06213

Please sign in to comment.