Skip to content

Commit

Permalink
🐛 Stop command stuck (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored Nov 19, 2023
1 parent 4894065 commit 02f2dbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
8 changes: 1 addition & 7 deletions src/clients/discord/discord.voice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class DiscordVoiceService {
},
);
this.playResource(resource);
console.log(resource);
}

tryJoinChannelAndEstablishVoiceConnection(
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/commands/disconnect.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -18,6 +19,7 @@ export class DisconnectCommand {
constructor(
private readonly discordVoiceService: DiscordVoiceService,
private readonly discordMessageService: DiscordMessageService,
private readonly playbackService: PlaybackService
) {}

@Handler()
Expand All @@ -30,6 +32,8 @@ export class DisconnectCommand {
],
});

this.discordVoiceService.stop(false);
this.playbackService.getPlaylistOrDefault().clear();
const disconnect = this.discordVoiceService.disconnect();

if (!disconnect.success) {
Expand Down
31 changes: 17 additions & 14 deletions src/commands/stop.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,28 @@ export class StopPlaybackCommand {

@Handler()
async handler(@IA() interaction: CommandInteraction): Promise<void> {
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'
}),
],
});
Expand Down

0 comments on commit 02f2dbe

Please sign in to comment.