mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { GuildQueue, Track, useQueue } from 'discord-player';
|
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|
import { Logger } from 'pino';
|
|
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
|
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
|
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
|
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
|
|
|
class PauseCommand extends BaseSlashCommandInteraction {
|
|
constructor() {
|
|
const data = new SlashCommandBuilder().setName('pause').setDescription('Toggle pause for the current track.');
|
|
super(data);
|
|
}
|
|
|
|
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
|
const { executionId, interaction } = params;
|
|
const logger = this.getLogger(this.name, executionId, interaction);
|
|
|
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
|
|
|
await this.runValidators({ interaction, queue, executionId }, [
|
|
checkInVoiceChannel,
|
|
checkSameVoiceChannel,
|
|
checkQueueExists,
|
|
checkQueueCurrentTrack
|
|
]);
|
|
|
|
const currentTrack: Track = queue.currentTrack!;
|
|
|
|
this.togglePauseState(queue, logger);
|
|
|
|
logger.debug('Responding with success embed.');
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor(await this.getEmbedUserAuthor(interaction))
|
|
.setDescription(
|
|
`**${this.embedOptions.icons.pauseResumed} ${
|
|
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
|
|
}**\n ${this.getDisplayTrackDurationAndUrl(currentTrack)}`
|
|
)
|
|
.setThumbnail(currentTrack.thumbnail)
|
|
.setColor(this.embedOptions.colors.success)
|
|
]
|
|
});
|
|
}
|
|
|
|
private togglePauseState(queue: GuildQueue, logger: Logger): void {
|
|
queue.node.setPaused(!queue.node.isPaused());
|
|
logger.debug(`Set paused state to ${queue.node.isPaused()}.`);
|
|
}
|
|
}
|
|
|
|
export default new PauseCommand();
|