From 99cbbf48508d1ef0c7928b507c78dc4f5754e757 Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Tue, 14 Mar 2023 20:58:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20interaction=20id=20in=20pa?= =?UTF-8?q?ge=20data=20map=20for=20playlist=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/playlist/playlist.command.ts | 18 +++++++++++++++--- .../playlist/playlist.interaction-collector.ts | 10 ++++++++++ src/utils/constants.ts | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/commands/playlist/playlist.command.ts b/src/commands/playlist/playlist.command.ts index cb291eb..d244041 100644 --- a/src/commands/playlist/playlist.command.ts +++ b/src/commands/playlist/playlist.command.ts @@ -57,11 +57,11 @@ export class PlaylistCommand { ): Promise { const page = dto.page ?? 0; - const response = await interaction.reply( + await interaction.reply( this.getReplyForPage(page) as InteractionReplyOptions, ); - this.pageData.set(response.id, page); + this.pageData.set(interaction.id, page); this.logger.debug( `Added '${interaction.id}' as a message id for page storage`, ); @@ -70,6 +70,7 @@ export class PlaylistCommand { this.logger.log( `Removed the components of message from interaction '${interaction.id}' because the event collector has reachted the timeout`, ); + this.pageData.delete(interaction.id); await interaction.editReply({ components: [], }); @@ -156,15 +157,26 @@ export class PlaylistCommand { chunks: Track[][], page: number, ): EmbedBuilder | undefined { + this.logger.verbose( + `Received request for page ${page} of playlist page chunks`, + ); const playlist = this.playbackService.getPlaylistOrDefault(); if (page >= chunks.length || page < 0) { + this.logger.warn(`Request for page chunks was out of range: ${page}`); return undefined; } const offset = page * 10; + const chunk = chunks[page]; - const content = chunks[page] + if (!chunk) { + this.logger.error( + `Failed to extract chunk from playlist chunks array with page ${page}`, + ); + } + + const content = chunk .map((track, index) => { const isCurrent = track === playlist.getActiveTrack(); diff --git a/src/commands/playlist/playlist.interaction-collector.ts b/src/commands/playlist/playlist.interaction-collector.ts index bf7e99a..462ad16 100644 --- a/src/commands/playlist/playlist.interaction-collector.ts +++ b/src/commands/playlist/playlist.interaction-collector.ts @@ -36,6 +36,9 @@ export class PlaylistInteractionCollector { @On('collect') async onCollect(interaction: ButtonInteraction): Promise { const targetPage = this.getInteraction(interaction); + this.logger.verbose( + `Extracted the target page ${targetPage} from the button interaction`, + ); if (targetPage === undefined) { await interaction.update({ @@ -55,6 +58,13 @@ export class PlaylistInteractionCollector { private getInteraction(interaction: ButtonInteraction): number | null { const current = this.playlistCommand.pageData.get(this.causeInteraction.id); + if (current === undefined) { + this.logger.warn( + `Unable to extract the current page from the cause interaction '${this.causeInteraction.id}'`, + ); + return undefined; + } + this.logger.debug( `Retrieved current page from command using id '${ this.causeInteraction.id diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 0883ea0..e73ec49 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,7 +3,7 @@ export const Constants = { Version: { Major: 0, Minor: 0, - Patch: 4, + Patch: 5, All: () => `${Constants.Metadata.Version.Major}.${Constants.Metadata.Version.Minor}.${Constants.Metadata.Version.Patch}`, },