From 6518681a350e15a9501cc31374e7c13d4af92ca8 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Sun, 18 Aug 2024 16:44:12 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Music=20skip=20and=20loop?= =?UTF-8?q?=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NekoMelody | 2 +- src/discord/MusicPlayer/Join.ts | 8 ++--- src/discord/MusicPlayer/Skip.ts | 2 +- src/providers/DiscordMusicPlayer.ts | 51 +++++------------------------ 4 files changed, 14 insertions(+), 49 deletions(-) diff --git a/NekoMelody b/NekoMelody index 3fbaf7a..738a9b7 160000 --- a/NekoMelody +++ b/NekoMelody @@ -1 +1 @@ -Subproject commit 3fbaf7a7b4c8f5920facbd3c299b10a8f51a1f99 +Subproject commit 738a9b710b5bda29abe08f93551e17990e0fc944 diff --git a/src/discord/MusicPlayer/Join.ts b/src/discord/MusicPlayer/Join.ts index decc3e5..77a7b3b 100644 --- a/src/discord/MusicPlayer/Join.ts +++ b/src/discord/MusicPlayer/Join.ts @@ -224,7 +224,7 @@ export async function joinVoiceChannelProcedure( if (!instance) return; - let previousTrack: ValidTracks | undefined; + let previousTrack: AudioInformation | null; let isLoopMessageSent = false; // Register Event Listeners @@ -233,10 +233,10 @@ export async function joinVoiceChannelProcedure( if (!current) return; const locale = await Locale.getGuildLocale(guild.id); - previousTrack = event.instance.getPreviousTrack(); + previousTrack = event.instance.nekoPlayer.getPreviousAudioInformation(); - //if (current !== previousTrack) isLoopMessageSent = false; - //else if (current === previousTrack && isLoopMessageSent) return; + if (current !== previousTrack) isLoopMessageSent = false; + else if (current === previousTrack && isLoopMessageSent) return; const row = new ActionRowBuilder(); // if (event.instance.queue.track[0] instanceof SpotifyTrack) diff --git a/src/discord/MusicPlayer/Skip.ts b/src/discord/MusicPlayer/Skip.ts index d1c2089..a0e2566 100644 --- a/src/discord/MusicPlayer/Skip.ts +++ b/src/discord/MusicPlayer/Skip.ts @@ -86,7 +86,7 @@ export default class Skip extends DiscordModule { embeds: [EMBEDS.NO_MUSIC_PLAYING(data, locale)] }); - instance.skipTrack(); + instance.skip(); if (!instance.nekoPlayer.getCurrentAudioInformation()) return await sendHybridInteractionMessageResponse(data, { diff --git a/src/providers/DiscordMusicPlayer.ts b/src/providers/DiscordMusicPlayer.ts index 3ce00f0..7cf8ab4 100644 --- a/src/providers/DiscordMusicPlayer.ts +++ b/src/providers/DiscordMusicPlayer.ts @@ -189,7 +189,7 @@ export class DiscordMusicPlayerInstance { public textChannel?: BaseGuildTextChannel | BaseGuildVoiceChannel; public voiceChannel: VoiceChannel | StageChannel; public voiceConnection?: VoiceConnection; - public previousTrack?: ValidTracks; + public previousTrack?: AudioInformation; public paused: boolean = false; @@ -209,38 +209,6 @@ export class DiscordMusicPlayerInstance { this.voiceChannel = voiceChannel; this.events = new EventEmitter(); - // this.player.on(AudioPlayerStatus.Idle, async (oldStage, newStage) => { - // //The player stopped - // if (newStage.status === AudioPlayerStatus.Idle && oldStage.status !== AudioPlayerStatus.Idle) { - // // Loop mode is set to current song - // if (this.loopMode === DiscordMusicPlayerLoopMode.Current) { - // if (this.queue.track.length !== 0) { - // this.previousTrack = this.queue.track[0]; - // this.playTrack(this.queue.track[0]); - // } - // return; - // } - - // // There are more songs in the queue, remove finished song and play the next one - // if (this.queue.track.length !== 0) { - // let previousTrack = this.queue.track.shift(); - // if (previousTrack) this.previousTrack = previousTrack; - - // if (this.queue.track.length > 0) { - // this.playTrack(this.queue.track[0]); - // } - // } - // } - // }); - - // this.player.on(AudioPlayerStatus.Playing, (oldState: any, newState: any) => { - // this.events.emit('playing', new PlayerPlayingEvent(this)); - // }); - - // this.player.on('error', (error: Error) => { - // this.events.emit('error', new PlayerErrorEvent(this, error)); - // }); - this.nekoPlayer.on('play', (information: AudioInformation) => { if (!this.nekoPlayer.stream) throw new Error('No input stream'); @@ -329,17 +297,14 @@ export class DiscordMusicPlayerInstance { this.paused = false; } - public async addTrackToQueue(track: ValidTracks) { - return await this.nekoPlayer.enqueue(track.url); + public async skip() { + if (!this.voiceConnection) throw new Error('No voice connection'); + this.discordPlayer.pause(true); + this.nekoPlayer.skip(); } - public async skipTrack() { - if (!this.voiceConnection) throw new Error('No voice connection'); - - if (this.nekoPlayer.getQueue().length === 0) return; - - await this.nekoPlayer.skip(); - if (this.paused) this.paused = false; + public async addTrackToQueue(track: ValidTracks) { + return await this.nekoPlayer.enqueue(track.url); } public clearQueue() { @@ -367,7 +332,7 @@ export class DiscordMusicPlayerInstance { this.queue.track = shuffleFixedFirst(this.queue.track); } - public getPreviousTrack(): ValidTracks | undefined { + public getPreviousTrack(): AudioInformation | undefined { return this.previousTrack; }