Implement stop command

This commit is contained in:
Manuel Ruwe 2022-12-17 22:39:33 +01:00
parent 7d8dc888c3
commit 4be0ca1537
2 changed files with 32 additions and 13 deletions

View File

@ -92,6 +92,13 @@ export class DiscordVoiceService {
this.createAndReturnOrGetAudioPlayer().pause();
}
/**
* Stops the audio player
*/
stop(force: boolean): boolean {
return this.createAndReturnOrGetAudioPlayer().stop(force);
}
/**
* Unpauses the current audio player
*/

View File

@ -1,23 +1,35 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
Command,
DiscordTransformedCommand,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { InteractionReplyOptions } from 'discord.js';
import { Command, DiscordCommand, UsePipes } from '@discord-nestjs/core';
import { CommandInteraction } from 'discord.js';
import { DiscordMessageService } from '../clients/discord/discord.message.service';
import { DiscordVoiceService } from '../clients/discord/discord.voice.service';
import { GenericCustomReply } from '../models/generic-try-handler';
import { PlaybackService } from '../playback/playback.service';
@Command({
name: 'stop',
description: 'Stop playback entirely and clear the current playlist',
})
@UsePipes(TransformPipe)
export class StopPlaybackCommand implements DiscordTransformedCommand<unknown> {
handler(
dto: unknown,
executionContext: TransformedCommandExecutionContext<any>,
): InteractionReplyOptions | string {
return 'nice';
export class StopPlaybackCommand implements DiscordCommand {
constructor(
private readonly playbackService: PlaybackService,
private readonly discordMessageService: DiscordMessageService,
private readonly discordVoiceService: DiscordVoiceService,
) {}
handler(CommandInteraction: CommandInteraction): GenericCustomReply {
this.playbackService.clear();
this.discordVoiceService.stop(false);
return {
embeds: [
this.discordMessageService.buildMessage({
title: 'Playlist cleared',
description:
'Playback was stopped and your playlist has been cleared',
}),
],
};
}
}