From 02f2dbec3c5e4de7206664f88599cfcfe09df84a Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Sun, 19 Nov 2023 19:20:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Stop=20command=20stuck=20(#244)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/discord/discord.voice.service.ts | 8 +---- src/commands/disconnect.command.ts | 4 +++ src/commands/stop.command.ts | 31 +++++++++++--------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/clients/discord/discord.voice.service.ts b/src/clients/discord/discord.voice.service.ts index 21eded2..1b81c51 100644 --- a/src/clients/discord/discord.voice.service.ts +++ b/src/clients/discord/discord.voice.service.ts @@ -50,7 +50,6 @@ export class DiscordVoiceService { }, ); this.playResource(resource); - console.log(resource); } tryJoinChannelAndEstablishVoiceConnection( @@ -138,9 +137,7 @@ export class DiscordVoiceService { */ @OnEvent('internal.voice.controls.stop') stop(force: boolean): boolean { - const stopped = this.createAndReturnOrGetAudioPlayer().stop(force); - this.eventEmitter.emit('playback.state.stop'); - return stopped; + return this.createAndReturnOrGetAudioPlayer().stop(force); } /** @@ -342,9 +339,6 @@ export class DiscordVoiceService { const activeTrack = playlist.getActiveTrack(); if (!activeTrack) { - this.logger.error( - "Failed to update ellapsed audio time because active track was unexpectitly undefined", - ); return; } diff --git a/src/commands/disconnect.command.ts b/src/commands/disconnect.command.ts index 8d52466..ae1e29a 100644 --- a/src/commands/disconnect.command.ts +++ b/src/commands/disconnect.command.ts @@ -7,6 +7,7 @@ import { CommandInteraction } from 'discord.js'; import { DiscordMessageService } from '../clients/discord/discord.message.service'; import { DiscordVoiceService } from '../clients/discord/discord.voice.service'; import { defaultMemberPermissions } from 'src/utils/environment'; +import { PlaybackService } from 'src/playback/playback.service'; @Injectable() @Command({ @@ -18,6 +19,7 @@ export class DisconnectCommand { constructor( private readonly discordVoiceService: DiscordVoiceService, private readonly discordMessageService: DiscordMessageService, + private readonly playbackService: PlaybackService ) {} @Handler() @@ -30,6 +32,8 @@ export class DisconnectCommand { ], }); + this.discordVoiceService.stop(false); + this.playbackService.getPlaylistOrDefault().clear(); const disconnect = this.discordVoiceService.disconnect(); if (!disconnect.success) { diff --git a/src/commands/stop.command.ts b/src/commands/stop.command.ts index c538679..96b8f62 100644 --- a/src/commands/stop.command.ts +++ b/src/commands/stop.command.ts @@ -24,25 +24,28 @@ export class StopPlaybackCommand { @Handler() async handler(@IA() interaction: CommandInteraction): Promise { - const hasActiveTrack = this.playbackService.getPlaylistOrDefault(); - const title = hasActiveTrack - ? 'Playback stopped successfully' - : 'Playback failed to stop'; - const description = hasActiveTrack - ? 'In addition, your playlist has been cleared' - : 'There is no active track in the queue'; - if (hasActiveTrack) { + const playlist = this.playbackService.getPlaylistOrDefault(); + + if (playlist.tracks.length === 0) { + await interaction.reply({ + embeds: [ + this.discordMessageService.buildErrorMessage({ + title: 'Unable to stop when nothing is playing' + }), + ], + }); + return; + } + + if (playlist.hasActiveTrack()) { this.discordVoiceService.stop(false); - // this.playbackService.getPlaylistOrDefault().clear(); } + playlist.clear(); await interaction.reply({ embeds: [ - this.discordMessageService[ - hasActiveTrack ? 'buildMessage' : 'buildErrorMessage' - ]({ - title, - description, + this.discordMessageService.buildMessage({ + title: 'Playback stopped' }), ], });