Skip to content

Commit

Permalink
[Fixes #278] Fix chunked paginator state embed generation where `page…
Browse files Browse the repository at this point in the history
…s < chunkedPages`
  • Loading branch information
gdude2002 committed Feb 28, 2024
1 parent 09db8bc commit 53e797c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 53e797c

Please sign in to comment.