From 4be0ca1537f9db5fc730f258c88ef864e19e621e Mon Sep 17 00:00:00 2001 From: Manuel Ruwe Date: Sat, 17 Dec 2022 22:39:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20stop=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/discord/discord.voice.service.ts | 7 ++++ src/commands/stop.command.ts | 38 +++++++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/clients/discord/discord.voice.service.ts b/src/clients/discord/discord.voice.service.ts index 32bbedb..ff7fa15 100644 --- a/src/clients/discord/discord.voice.service.ts +++ b/src/clients/discord/discord.voice.service.ts @@ -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 */ diff --git a/src/commands/stop.command.ts b/src/commands/stop.command.ts index c5d9e42..a9b7977 100644 --- a/src/commands/stop.command.ts +++ b/src/commands/stop.command.ts @@ -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 { - handler( - dto: unknown, - executionContext: TransformedCommandExecutionContext, - ): 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', + }), + ], + }; } }