commonMain.builder.interaction.ModalBuilder.kt Maven / Gradle / Ivy
package dev.kord.rest.builder.interaction
import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.DiscordModal
import dev.kord.rest.builder.RequestBuilder
import dev.kord.rest.builder.component.ActionRowBuilder
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@KordDsl
public class ModalBuilder(
public var title: String,
public var customId: String
) : RequestBuilder {
public val components: MutableList = mutableListOf()
/**
* Adds an Action Row to the modal, configured by the [builder].
*/
public inline fun actionRow(builder: ActionRowBuilder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
components.add(ActionRowBuilder().apply(builder))
}
override fun toRequest(): DiscordModal = DiscordModal(
title,
customId,
components.map { it.build() }
)
}