From 981be707f04af0fd21481075683c63a3d0d42a2f Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 12 Dec 2023 15:29:01 +0100 Subject: [PATCH 1/3] fix: Small changes to new action buttons --- .../commands/player/nowplaying.ts | 4 +- src/interactions/commands/player/queue.ts | 37 +++++++++---------- ...button.ts => action-pauseresume-button.ts} | 6 +-- ...ck-button.ts => action-previous-button.ts} | 6 +-- ...g-skip-button.ts => action-skip-button.ts} | 6 +-- 5 files changed, 28 insertions(+), 31 deletions(-) rename src/interactions/components/{nowplaying-playpause-button.ts => action-pauseresume-button.ts} (95%) rename src/interactions/components/{nowplaying-back-button.ts => action-previous-button.ts} (96%) rename src/interactions/components/{nowplaying-skip-button.ts => action-skip-button.ts} (95%) diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index 7a3200a..ca47d63 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -44,12 +44,12 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { const displayQueueRepeatMode: string = this.getDisplayQueueRepeatMode(queue); const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue); - const customId: string = `nowplaying-skip-button_${currentTrack.id}`; + const customId: string = `action-skip-button_${currentTrack.id}`; logger.debug(`Generated custom id for skip button: ${customId}`); const skipButton: APIButtonComponent = new ButtonBuilder() .setCustomId(customId) - .setLabel('Skip track') + .setLabel('Skip') .setStyle(ButtonStyle.Secondary) .setEmoji(this.embedOptions.icons.nextTrack) .toJSON(); diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index fa506fd..61de60c 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -68,30 +68,27 @@ class QueueCommand extends BaseSlashCommandInteraction { logger.debug('Queue exists with current track, gathering information.'); const playPauseButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(`nowplaying-playpause-button_${currentTrack.id}`) - // .setLabel('Pause/Resume track') + .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]; - if (queue.history.tracks.data.length > 0) { - const backButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(`nowplaying-back-button_${currentTrack.id}`) - // .setLabel('Previous track') - .setStyle(ButtonStyle.Secondary) - .setEmoji(this.embedOptions.icons.previousTrack) - .toJSON(); - components.unshift(backButton); - } - if (queue.tracks.data.length > 0) { - const skipButton: APIButtonComponent = new ButtonBuilder() - .setCustomId(`nowplaying-skip-button_${currentTrack.id}`) - // .setLabel('Skip track') - .setStyle(ButtonStyle.Secondary) - .setEmoji(this.embedOptions.icons.nextTrack) - .toJSON(); - components.push(skipButton); - } + 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.unshift(previousButton); + const skipButton: APIButtonComponent = new ButtonBuilder() + .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, diff --git a/src/interactions/components/nowplaying-playpause-button.ts b/src/interactions/components/action-pauseresume-button.ts similarity index 95% rename from src/interactions/components/nowplaying-playpause-button.ts rename to src/interactions/components/action-pauseresume-button.ts index 346295b..370005b 100644 --- a/src/interactions/components/nowplaying-playpause-button.ts +++ b/src/interactions/components/action-pauseresume-button.ts @@ -5,9 +5,9 @@ import { BaseComponentParams, BaseComponentReturnType } from '../../types/intera import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator'; import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; -class NowplayingPlayPauseButton extends BaseComponentInteraction { +class ActionPauseResumeButton extends BaseComponentInteraction { constructor() { - super('nowplaying-playpause-button'); + super('action-pauseresume-button'); } async execute(params: BaseComponentParams): BaseComponentReturnType { @@ -89,4 +89,4 @@ class NowplayingPlayPauseButton extends BaseComponentInteraction { } } -export default new NowplayingPlayPauseButton(); +export default new ActionPauseResumeButton(); diff --git a/src/interactions/components/nowplaying-back-button.ts b/src/interactions/components/action-previous-button.ts similarity index 96% rename from src/interactions/components/nowplaying-back-button.ts rename to src/interactions/components/action-previous-button.ts index 94744fe..158c7ad 100644 --- a/src/interactions/components/nowplaying-back-button.ts +++ b/src/interactions/components/action-previous-button.ts @@ -6,9 +6,9 @@ import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; import { Logger } from 'pino'; -class NowplayingBackButton extends BaseComponentInteraction { +class ActionPreviousButton extends BaseComponentInteraction { constructor() { - super('nowplaying-back-button'); + super('action-previous-button'); } async execute(params: BaseComponentParams): BaseComponentReturnType { @@ -108,4 +108,4 @@ class NowplayingBackButton extends BaseComponentInteraction { } } -export default new NowplayingBackButton(); +export default new ActionPreviousButton(); diff --git a/src/interactions/components/nowplaying-skip-button.ts b/src/interactions/components/action-skip-button.ts similarity index 95% rename from src/interactions/components/nowplaying-skip-button.ts rename to src/interactions/components/action-skip-button.ts index bb7dd6a..012f269 100644 --- a/src/interactions/components/nowplaying-skip-button.ts +++ b/src/interactions/components/action-skip-button.ts @@ -5,9 +5,9 @@ import { BaseComponentParams, BaseComponentReturnType } from '../../types/intera import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator'; import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator'; -class NowplayingSkipButton extends BaseComponentInteraction { +class ActionSkipButton extends BaseComponentInteraction { constructor() { - super('nowplaying-skip-button'); + super('action-skip-button'); } async execute(params: BaseComponentParams): BaseComponentReturnType { @@ -83,4 +83,4 @@ class NowplayingSkipButton extends BaseComponentInteraction { } } -export default new NowplayingSkipButton(); +export default new ActionSkipButton(); From fac39e45cbd752db7148ea4be590a5cd05a88fb9 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 12 Dec 2023 15:39:09 +0100 Subject: [PATCH 2/3] fix: Add new action buttons also to /history command --- src/interactions/commands/player/history.ts | 44 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/interactions/commands/player/history.ts b/src/interactions/commands/player/history.ts index 1aea167..ca7c3d0 100644 --- a/src/interactions/commands/player/history.ts +++ b/src/interactions/commands/player/history.ts @@ -1,5 +1,16 @@ import { GuildQueue, GuildQueueHistory, Track, useHistory, useQueue } from 'discord-player'; -import { ChatInputCommandInteraction, EmbedBuilder, EmbedFooterData, SlashCommandBuilder } from 'discord.js'; +import { + APIActionRowComponent, + APIButtonComponent, + APIMessageActionRowComponent, + ButtonBuilder, + ButtonStyle, + ChatInputCommandInteraction, + ComponentType, + EmbedBuilder, + EmbedFooterData, + SlashCommandBuilder +} from 'discord.js'; import { Logger } from 'pino'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; @@ -64,6 +75,34 @@ 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 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.unshift(previousButton); + const skipButton: APIButtonComponent = new ButtonBuilder() + .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 + }; + logger.debug('Responding with info embed.'); await interaction.editReply({ embeds: [ @@ -81,7 +120,8 @@ class HistoryCommand extends BaseSlashCommandInteraction { .setThumbnail(this.getTrackThumbnailUrl(currentTrack)) .setFooter(this.getDisplayFullFooterInfo(interaction, history)) .setColor(this.embedOptions.colors.info) - ] + ], + components: [embedActionRow] }); return Promise.resolve(); } From 4b646e24dbf0a2da775cdb1ae412c6bb21dca0c8 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 12 Dec 2023 15:42:32 +0100 Subject: [PATCH 3/3] 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')