From 53e797c22b746062b7265e0a63b70f30baaf9ab3 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 28 Feb 2024 10:40:41 +0000 Subject: [PATCH] [Fixes #278] Fix chunked paginator state embed generation where `pages < chunkedPages` --- .../extensions/pagination/BasePaginator.kt | 41 +++++++++++-------- .../extensions/PaginatorTestExtension.kt | 16 ++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/pagination/BasePaginator.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/pagination/BasePaginator.kt index fb0b858d3d..e772e3e2d6 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/pagination/BasePaginator.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/pagination/BasePaginator.kt @@ -16,6 +16,7 @@ import com.kotlindiscord.kord.extensions.pagination.pages.Pages import dev.kord.core.Kord import dev.kord.core.behavior.UserBehavior import dev.kord.core.entity.ReactionEmoji +import dev.kord.rest.builder.message.EmbedBuilder import dev.kord.rest.builder.message.MessageBuilder import dev.kord.rest.builder.message.embed import io.github.oshai.kotlinlogging.KLogger @@ -157,22 +158,30 @@ public abstract class BasePaginator( } if (chunkedPages > 1) { - embed { - logger.debug { "Building footer page" } - - Page(bundle) { - color = DISCORD_BLURPLE - }.build( - localeObj, - currentPageNum, - chunkedPages, - pages.groups[currentGroup]!!.size, - groupEmoji, - allGroups.indexOf(currentGroup), - allGroups.size, - shouldPutFooterInDescription = true, - mutator = mutator?.pageMutator - )() + val builder = EmbedBuilder() + + logger.debug { "Building footer page" } + + Page(bundle) { + color = DISCORD_BLURPLE + }.build( + localeObj, + currentPageNum, + chunkedPages, + pages.groups[currentGroup]!!.size, + groupEmoji, + allGroups.indexOf(currentGroup), + allGroups.size, + shouldPutFooterInDescription = true, + mutator = mutator?.pageMutator + )(builder) + + if (!builder.description.isNullOrEmpty()) { + if (this.embeds == null) { + this.embeds = mutableListOf(builder) + } else { + this.embeds!!.add(builder) + } } } diff --git a/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/PaginatorTestExtension.kt b/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/PaginatorTestExtension.kt index 4f5141fe89..f6bb8ccf92 100644 --- a/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/PaginatorTestExtension.kt +++ b/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/PaginatorTestExtension.kt @@ -84,6 +84,22 @@ public class PaginatorTestExtension : Extension() { } } + publicSubCommand { + name = "chunked-small" + description = "Test a chunked default-group paginator with one page." + + action { + editingPaginator { + chunkedPages = 2 + + page { + title = "Page one!" + description = "Page one!" + } + }.send() + } + } + publicSubCommand { name = "custom-one" description = "Test a custom-grouped paginator with pages, approach 1."