-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
/list-servers
now pages the response (#111)
- Loading branch information
Showing
3 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/de/darkatra/vrising/discord/commands/parameters/PageParameter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.darkatra.vrising.discord.commands.parameters | ||
|
||
import de.darkatra.vrising.discord.commands.exceptions.ValidationException | ||
import dev.kord.core.entity.interaction.ChatInputCommandInteraction | ||
import dev.kord.rest.builder.interaction.GlobalChatInputCreateBuilder | ||
import dev.kord.rest.builder.interaction.integer | ||
|
||
object PageParameter { | ||
const val NAME = "page" | ||
|
||
fun validate(page: Int) { | ||
if (page < 0) { | ||
throw ValidationException("'$NAME' must be greater than or equal to zero. Rejected: $page") | ||
} | ||
} | ||
} | ||
|
||
fun GlobalChatInputCreateBuilder.addPageParameter(required: Boolean = true) { | ||
integer( | ||
name = PageParameter.NAME, | ||
description = "The page. Defaults to 0, the first page." | ||
) { | ||
this.required = required | ||
} | ||
} | ||
|
||
fun ChatInputCommandInteraction.getPageParameter(): Int? { | ||
return command.integers[PageParameter.NAME]?.let { Math.toIntExact(it) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters