2022-12-16 16:10:16 +01:00
|
|
|
import { TransformPipe } from '@discord-nestjs/common';
|
|
|
|
|
2022-12-17 22:39:33 +01:00
|
|
|
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 { PlaybackService } from '../playback/playback.service';
|
2022-12-16 16:10:16 +01:00
|
|
|
|
|
|
|
@Command({
|
|
|
|
name: 'stop',
|
|
|
|
description: 'Stop playback entirely and clear the current playlist',
|
|
|
|
})
|
|
|
|
@UsePipes(TransformPipe)
|
2022-12-17 22:39:33 +01:00
|
|
|
export class StopPlaybackCommand implements DiscordCommand {
|
|
|
|
constructor(
|
|
|
|
private readonly playbackService: PlaybackService,
|
|
|
|
private readonly discordMessageService: DiscordMessageService,
|
|
|
|
private readonly discordVoiceService: DiscordVoiceService,
|
|
|
|
) {}
|
2022-12-20 11:03:24 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2023-01-22 21:53:50 +01:00
|
|
|
async handler(interaction: CommandInteraction): Promise<void> {
|
|
|
|
const hasActiveTrack = this.playbackService.hasActiveTrack();
|
|
|
|
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';
|
2023-01-16 22:35:51 +01:00
|
|
|
if (hasActiveTrack) {
|
|
|
|
this.playbackService.clear();
|
|
|
|
this.discordVoiceService.stop(false);
|
|
|
|
}
|
2022-12-17 22:39:33 +01:00
|
|
|
|
2023-01-22 21:53:50 +01:00
|
|
|
await interaction.reply({
|
2022-12-17 22:39:33 +01:00
|
|
|
embeds: [
|
2023-01-22 21:53:50 +01:00
|
|
|
this.discordMessageService[
|
|
|
|
hasActiveTrack ? 'buildMessage' : 'buildErrorMessage'
|
|
|
|
]({
|
2023-01-16 22:35:51 +01:00
|
|
|
title: title,
|
|
|
|
description: description,
|
2022-12-17 22:39:33 +01:00
|
|
|
}),
|
|
|
|
],
|
2023-01-22 21:53:50 +01:00
|
|
|
});
|
2022-12-16 16:10:16 +01:00
|
|
|
}
|
|
|
|
}
|