discord-jellyfin-bot/src/commands/stop.command.ts

41 lines
1.6 KiB
TypeScript
Raw Normal View History

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 { GenericCustomReply } from '../models/generic-try-handler';
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
2022-12-17 22:39:33 +01:00
handler(CommandInteraction: CommandInteraction): GenericCustomReply {
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'
if (hasActiveTrack) {
this.playbackService.clear();
this.discordVoiceService.stop(false);
}
2022-12-17 22:39:33 +01:00
return {
embeds: [
this.discordMessageService[hasActiveTrack ? 'buildMessage' : 'buildErrorMessage']({
title: title,
description: description,
2022-12-17 22:39:33 +01:00
}),
],
};
2022-12-16 16:10:16 +01:00
}
}