Skip to content

Commit

Permalink
Suspending paginator DSLs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Aug 10, 2021
1 parent 6e59997 commit d0a9171
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.kord.core.entity.Message
import dev.kord.core.entity.User
import dev.kord.core.event.message.MessageCreateEvent
import dev.kord.rest.builder.message.create.MessageCreateBuilder
import dev.kord.rest.builder.message.modify.MessageModifyBuilder

/**
* Command context object representing the context given to message commands.
Expand Down Expand Up @@ -85,7 +86,7 @@ public open class MessageCommandContext<T : Arguments>(
targetChannel: MessageChannelBehavior? = null,
targetMessage: Message? = null,

body: PaginatorBuilder.() -> Unit
body: suspend PaginatorBuilder.() -> Unit
): MessageButtonPaginator {
val builder = PaginatorBuilder(command.extension, getLocale(), defaultGroup = defaultGroup)

Expand Down Expand Up @@ -137,4 +138,24 @@ public open class MessageCommandContext<T : Arguments>(

return components
}

/**
* Convenience function for adding components to your message via the [Components] class.
*
* @see Components
*/
public suspend fun MessageModifyBuilder.components(
timeoutSeconds: Long? = null,
body: suspend Components.() -> Unit
): Components {
val components = Components(command.extension)

body(components)

with(components) {
setup(timeoutSeconds)
}

return components
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public open class SlashCommandContext<T : Arguments>(
*/
public suspend fun paginator(
defaultGroup: String = "",
body: PaginatorBuilder.() -> Unit
body: suspend PaginatorBuilder.() -> Unit
): InteractionButtonPaginator {
val builder = PaginatorBuilder(command.extension, getLocale(), defaultGroup = defaultGroup)

Expand Down

0 comments on commit d0a9171

Please sign in to comment.