From 4b646e24dbf0a2da775cdb1ae412c6bb21dca0c8 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 12 Dec 2023 15:42:32 +0100 Subject: [PATCH] Add updated action buttons to /nowplaying --- src/interactions/commands/player/history.ts | 20 ++++++++------ .../commands/player/nowplaying.ts | 27 +++++++++++++++---- src/interactions/commands/player/queue.ts | 20 ++++++++------ 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/interactions/commands/player/history.ts b/src/interactions/commands/player/history.ts index ca7c3d0..ea127a0 100644 --- a/src/interactions/commands/player/history.ts +++ b/src/interactions/commands/player/history.ts @@ -75,13 +75,8 @@ class HistoryCommand extends BaseSlashCommandInteraction { ) { logger.debug('History exists with current track, gathering information.'); - const playPauseButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(`action-pauseresume-button_${currentTrack.id}`) - .setLabel(queue.node.isPaused() ? 'Resume' : 'Pause') - .setStyle(ButtonStyle.Secondary) - .setEmoji(this.embedOptions.icons.pauseResumeTrack) - .toJSON(); - const components: APIMessageActionRowComponent[] = [playPauseButton]; + const components: APIMessageActionRowComponent[] = []; + const previousButton: APIButtonComponent = new ButtonBuilder() .setDisabled(queue.history.tracks.data.length > 0 ? false : true) .setCustomId(`action-previous-button_${currentTrack.id}`) @@ -89,7 +84,16 @@ class HistoryCommand extends BaseSlashCommandInteraction { .setStyle(ButtonStyle.Secondary) .setEmoji(this.embedOptions.icons.previousTrack) .toJSON(); - components.unshift(previousButton); + components.push(previousButton); + + const playPauseButton: APIButtonComponent = new ButtonBuilder() + .setCustomId(`action-pauseresume-button_${currentTrack.id}`) + .setLabel(queue.node.isPaused() ? 'Resume' : 'Pause') + .setStyle(ButtonStyle.Secondary) + .setEmoji(this.embedOptions.icons.pauseResumeTrack) + .toJSON(); + components.push(playPauseButton); + const skipButton: APIButtonComponent = new ButtonBuilder() .setCustomId(`action-skip-button_${currentTrack.id}`) .setLabel('Skip') diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index ca47d63..c4f3117 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -44,19 +44,36 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { const displayQueueRepeatMode: string = this.getDisplayQueueRepeatMode(queue); const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue); - const customId: string = `action-skip-button_${currentTrack.id}`; - logger.debug(`Generated custom id for skip button: ${customId}`); + const components: APIMessageActionRowComponent[] = []; + + const previousButton: APIButtonComponent = new ButtonBuilder() + .setDisabled(queue.history.tracks.data.length > 0 ? false : true) + .setCustomId(`action-previous-button_${currentTrack.id}`) + .setLabel('Previous') + .setStyle(ButtonStyle.Secondary) + .setEmoji(this.embedOptions.icons.previousTrack) + .toJSON(); + components.push(previousButton); + + const playPauseButton: APIButtonComponent = new ButtonBuilder() + .setCustomId(`action-pauseresume-button_${currentTrack.id}`) + .setLabel(queue.node.isPaused() ? 'Resume' : 'Pause') + .setStyle(ButtonStyle.Secondary) + .setEmoji(this.embedOptions.icons.pauseResumeTrack) + .toJSON(); + components.push(playPauseButton); const skipButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(customId) + .setCustomId(`action-skip-button_${currentTrack.id}`) .setLabel('Skip') .setStyle(ButtonStyle.Secondary) .setEmoji(this.embedOptions.icons.nextTrack) .toJSON(); + components.push(skipButton); const embedActionRow: APIActionRowComponent = { type: ComponentType.ActionRow, - components: [skipButton] + components }; logger.debug('Sending info embed with action row components.'); @@ -78,7 +95,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { .setThumbnail(this.getTrackThumbnailUrl(queue.currentTrack!)) .setColor(this.embedOptions.colors.info) ], - components: [embedActionRow as APIActionRowComponent] + components: [embedActionRow] }); } diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index 61de60c..ad47618 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -67,13 +67,8 @@ class QueueCommand extends BaseSlashCommandInteraction { ) { logger.debug('Queue exists with current track, gathering information.'); - const playPauseButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(`action-pauseresume-button_${currentTrack.id}`) - .setLabel(queue.node.isPaused() ? 'Resume' : 'Pause') - .setStyle(ButtonStyle.Secondary) - .setEmoji(this.embedOptions.icons.pauseResumeTrack) - .toJSON(); - const components: APIMessageActionRowComponent[] = [playPauseButton]; + const components: APIMessageActionRowComponent[] = []; + const previousButton: APIButtonComponent = new ButtonBuilder() .setDisabled(queue.history.tracks.data.length > 0 ? false : true) .setCustomId(`action-previous-button_${currentTrack.id}`) @@ -81,7 +76,16 @@ class QueueCommand extends BaseSlashCommandInteraction { .setStyle(ButtonStyle.Secondary) .setEmoji(this.embedOptions.icons.previousTrack) .toJSON(); - components.unshift(previousButton); + components.push(previousButton); + + const playPauseButton: APIButtonComponent = new ButtonBuilder() + .setCustomId(`action-pauseresume-button_${currentTrack.id}`) + .setLabel(queue.node.isPaused() ? 'Resume' : 'Pause') + .setStyle(ButtonStyle.Secondary) + .setEmoji(this.embedOptions.icons.pauseResumeTrack) + .toJSON(); + components.push(playPauseButton); + const skipButton: APIButtonComponent = new ButtonBuilder() .setCustomId(`action-skip-button_${currentTrack.id}`) .setLabel('Skip')