🐛 Fix interaction id in page data map for playlist command

This commit is contained in:
Manuel 2023-03-14 20:58:35 +01:00
parent 1632c2345e
commit 99cbbf4850
3 changed files with 26 additions and 4 deletions

View File

@ -57,11 +57,11 @@ export class PlaylistCommand {
): Promise<void> { ): Promise<void> {
const page = dto.page ?? 0; const page = dto.page ?? 0;
const response = await interaction.reply( await interaction.reply(
this.getReplyForPage(page) as InteractionReplyOptions, this.getReplyForPage(page) as InteractionReplyOptions,
); );
this.pageData.set(response.id, page); this.pageData.set(interaction.id, page);
this.logger.debug( this.logger.debug(
`Added '${interaction.id}' as a message id for page storage`, `Added '${interaction.id}' as a message id for page storage`,
); );
@ -70,6 +70,7 @@ export class PlaylistCommand {
this.logger.log( this.logger.log(
`Removed the components of message from interaction '${interaction.id}' because the event collector has reachted the timeout`, `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({ await interaction.editReply({
components: [], components: [],
}); });
@ -156,15 +157,26 @@ export class PlaylistCommand {
chunks: Track[][], chunks: Track[][],
page: number, page: number,
): EmbedBuilder | undefined { ): EmbedBuilder | undefined {
this.logger.verbose(
`Received request for page ${page} of playlist page chunks`,
);
const playlist = this.playbackService.getPlaylistOrDefault(); const playlist = this.playbackService.getPlaylistOrDefault();
if (page >= chunks.length || page < 0) { if (page >= chunks.length || page < 0) {
this.logger.warn(`Request for page chunks was out of range: ${page}`);
return undefined; return undefined;
} }
const offset = page * 10; 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) => { .map((track, index) => {
const isCurrent = track === playlist.getActiveTrack(); const isCurrent = track === playlist.getActiveTrack();

View File

@ -36,6 +36,9 @@ export class PlaylistInteractionCollector {
@On('collect') @On('collect')
async onCollect(interaction: ButtonInteraction): Promise<void> { async onCollect(interaction: ButtonInteraction): Promise<void> {
const targetPage = this.getInteraction(interaction); const targetPage = this.getInteraction(interaction);
this.logger.verbose(
`Extracted the target page ${targetPage} from the button interaction`,
);
if (targetPage === undefined) { if (targetPage === undefined) {
await interaction.update({ await interaction.update({
@ -55,6 +58,13 @@ export class PlaylistInteractionCollector {
private getInteraction(interaction: ButtonInteraction): number | null { private getInteraction(interaction: ButtonInteraction): number | null {
const current = this.playlistCommand.pageData.get(this.causeInteraction.id); 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( this.logger.debug(
`Retrieved current page from command using id '${ `Retrieved current page from command using id '${
this.causeInteraction.id this.causeInteraction.id

View File

@ -3,7 +3,7 @@ export const Constants = {
Version: { Version: {
Major: 0, Major: 0,
Minor: 0, Minor: 0,
Patch: 4, Patch: 5,
All: () => All: () =>
`${Constants.Metadata.Version.Major}.${Constants.Metadata.Version.Minor}.${Constants.Metadata.Version.Patch}`, `${Constants.Metadata.Version.Major}.${Constants.Metadata.Version.Minor}.${Constants.Metadata.Version.Patch}`,
}, },