🐛 Stop command stuck (#244)

This commit is contained in:
Manuel 2023-11-19 19:20:52 +01:00 committed by GitHub
parent 4894065d15
commit 02f2dbec3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 22 deletions

View File

@ -50,7 +50,6 @@ export class DiscordVoiceService {
}, },
); );
this.playResource(resource); this.playResource(resource);
console.log(resource);
} }
tryJoinChannelAndEstablishVoiceConnection( tryJoinChannelAndEstablishVoiceConnection(
@ -138,9 +137,7 @@ export class DiscordVoiceService {
*/ */
@OnEvent('internal.voice.controls.stop') @OnEvent('internal.voice.controls.stop')
stop(force: boolean): boolean { stop(force: boolean): boolean {
const stopped = this.createAndReturnOrGetAudioPlayer().stop(force); return this.createAndReturnOrGetAudioPlayer().stop(force);
this.eventEmitter.emit('playback.state.stop');
return stopped;
} }
/** /**
@ -342,9 +339,6 @@ export class DiscordVoiceService {
const activeTrack = playlist.getActiveTrack(); const activeTrack = playlist.getActiveTrack();
if (!activeTrack) { if (!activeTrack) {
this.logger.error(
"Failed to update ellapsed audio time because active track was unexpectitly undefined",
);
return; return;
} }

View File

@ -7,6 +7,7 @@ import { CommandInteraction } from 'discord.js';
import { DiscordMessageService } from '../clients/discord/discord.message.service'; import { DiscordMessageService } from '../clients/discord/discord.message.service';
import { DiscordVoiceService } from '../clients/discord/discord.voice.service'; import { DiscordVoiceService } from '../clients/discord/discord.voice.service';
import { defaultMemberPermissions } from 'src/utils/environment'; import { defaultMemberPermissions } from 'src/utils/environment';
import { PlaybackService } from 'src/playback/playback.service';
@Injectable() @Injectable()
@Command({ @Command({
@ -18,6 +19,7 @@ export class DisconnectCommand {
constructor( constructor(
private readonly discordVoiceService: DiscordVoiceService, private readonly discordVoiceService: DiscordVoiceService,
private readonly discordMessageService: DiscordMessageService, private readonly discordMessageService: DiscordMessageService,
private readonly playbackService: PlaybackService
) {} ) {}
@Handler() @Handler()
@ -30,6 +32,8 @@ export class DisconnectCommand {
], ],
}); });
this.discordVoiceService.stop(false);
this.playbackService.getPlaylistOrDefault().clear();
const disconnect = this.discordVoiceService.disconnect(); const disconnect = this.discordVoiceService.disconnect();
if (!disconnect.success) { if (!disconnect.success) {

View File

@ -24,25 +24,28 @@ export class StopPlaybackCommand {
@Handler() @Handler()
async handler(@IA() interaction: CommandInteraction): Promise<void> { async handler(@IA() interaction: CommandInteraction): Promise<void> {
const hasActiveTrack = this.playbackService.getPlaylistOrDefault(); const playlist = this.playbackService.getPlaylistOrDefault();
const title = hasActiveTrack
? 'Playback stopped successfully' if (playlist.tracks.length === 0) {
: 'Playback failed to stop'; await interaction.reply({
const description = hasActiveTrack embeds: [
? 'In addition, your playlist has been cleared' this.discordMessageService.buildErrorMessage({
: 'There is no active track in the queue'; title: 'Unable to stop when nothing is playing'
if (hasActiveTrack) { }),
this.discordVoiceService.stop(false); ],
// this.playbackService.getPlaylistOrDefault().clear(); });
return;
} }
if (playlist.hasActiveTrack()) {
this.discordVoiceService.stop(false);
}
playlist.clear();
await interaction.reply({ await interaction.reply({
embeds: [ embeds: [
this.discordMessageService[ this.discordMessageService.buildMessage({
hasActiveTrack ? 'buildMessage' : 'buildErrorMessage' title: 'Playback stopped'
]({
title,
description,
}), }),
], ],
}); });