Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms support adjustments #534

Merged
merged 4 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package dev.kord.core.behavior.interaction

import dev.kord.common.entity.Snowflake
import dev.kord.core.Kord
import dev.kord.core.behavior.interaction.response.EphemeralInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.EphemeralMessageInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.PublicInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
import dev.kord.core.entity.Message
import dev.kord.core.exception.EntityNotFoundException
Expand All @@ -25,7 +23,7 @@ public interface ActionInteractionBehavior : InteractionBehavior {
/**
* Acknowledges an interaction ephemerally.
*
* @return [EphemeralInteractionResponseBehavior] Ephemeral acknowledgement of the interaction.
* @return [EphemeralMessageInteractionResponseBehavior] Ephemeral acknowledgement of the interaction.
*/
public suspend fun acknowledgeEphemeral(): EphemeralMessageInteractionResponseBehavior {
kord.rest.interaction.acknowledge(id, token, ephemeral = true)
Expand All @@ -35,9 +33,9 @@ public interface ActionInteractionBehavior : InteractionBehavior {
/**
* Acknowledges an interaction.
*
* @return [PublicInteractionResponseBehavior] public acknowledgement of an interaction.
* @return [PublicMessageInteractionResponseBehavior] public acknowledgement of an interaction.
*/
public suspend fun acknowledgePublic(): PublicInteractionResponseBehavior {
public suspend fun acknowledgePublic(): PublicMessageInteractionResponseBehavior {
kord.rest.interaction.acknowledge(id, token, ephemeral = false)
return PublicMessageInteractionResponseBehavior(applicationId, token, kord)
}
Expand All @@ -62,29 +60,29 @@ public interface ActionInteractionBehavior : InteractionBehavior {


/**
* Acknowledges an interaction and responds with [PublicInteractionResponseBehavior].
* Acknowledges an interaction and responds with [PublicMessageInteractionResponseBehavior].
*
* @param builder [InteractionResponseCreateBuilder] used to create a public response.
* @return [PublicInteractionResponseBehavior] public response to the interaction.
* @return [PublicMessageInteractionResponseBehavior] public response to the interaction.
*/
public suspend inline fun ActionInteractionBehavior.respondPublic(
builder: InteractionResponseCreateBuilder.() -> Unit
): PublicInteractionResponseBehavior {
): PublicMessageInteractionResponseBehavior {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
kord.rest.interaction.createInteractionResponse(id, token, ephemeral = false, builder)
return PublicMessageInteractionResponseBehavior(applicationId, token, kord)
}


/**
* Acknowledges an interaction and responds with [EphemeralInteractionResponseBehavior] with ephemeral flag.
* Acknowledges an interaction and responds with [EphemeralMessageInteractionResponseBehavior] with ephemeral flag.
*
* @param builder [InteractionResponseCreateBuilder] used to a create an ephemeral response.
* @return [InteractionResponseBehavior] ephemeral response to the interaction.
* @param builder [InteractionResponseCreateBuilder] used to create an ephemeral response.
* @return [EphemeralMessageInteractionResponseBehavior] ephemeral response to the interaction.
*/
public suspend inline fun ActionInteractionBehavior.respondEphemeral(
builder: InteractionResponseCreateBuilder.() -> Unit
): EphemeralInteractionResponseBehavior {
): EphemeralMessageInteractionResponseBehavior {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
kord.rest.interaction.createInteractionResponse(id, token, ephemeral = true, builder)
return EphemeralMessageInteractionResponseBehavior(applicationId, token, kord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dev.kord.common.entity.MessageFlags
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.Optional
import dev.kord.core.Kord
import dev.kord.core.behavior.interaction.response.EphemeralInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.EphemeralMessageInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.PopupInteractionResponseBehavior
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
Expand Down Expand Up @@ -148,7 +147,7 @@ public suspend fun ComponentInteractionBehavior.acknowledgePublicUpdateMessage(
*/
public suspend fun ComponentInteractionBehavior.acknowledgeEphemeralUpdateMessage(
builder: UpdateMessageInteractionResponseCreateBuilder.() -> Unit
): EphemeralInteractionResponseBehavior {
): EphemeralMessageInteractionResponseBehavior {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }

val request = UpdateMessageInteractionResponseCreateBuilder().apply(builder).toRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import dev.kord.core.entity.interaction.followup.EphemeralFollowupMessage
import dev.kord.core.entity.interaction.followup.PublicFollowupMessage
import dev.kord.core.exception.EntityNotFoundException
import dev.kord.rest.builder.message.create.FollowupMessageCreateBuilder
import dev.kord.rest.builder.message.modify.InteractionResponseModifyBuilder
import dev.kord.rest.request.RestRequestException
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* The behavior of a [Discord ActionInteraction Response](https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction)
*/
public interface InteractionResponseBehavior : KordObject, Strategizable {
public sealed interface InteractionResponseBehavior : KordObject, Strategizable {
public val applicationId: Snowflake
public val token: String

Expand Down Expand Up @@ -57,4 +56,3 @@ public suspend inline fun InteractionResponseBehavior.followUpEphemeral(builder:
val message = kord.rest.interaction.createFollowupMessage(applicationId, token, ephemeral = true, builder)
return EphemeralFollowupMessage(Message(message.toData(), kord), applicationId, token, kord)
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.kord.core.behavior.interaction.response

import dev.kord.common.entity.Snowflake
import dev.kord.core.Kord
import dev.kord.core.entity.Strategizable
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.request.RestRequestException
Expand Down
6 changes: 3 additions & 3 deletions rest/src/main/kotlin/builder/component/SelectMenuBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SelectMenuBuilder(
* The range of values that can be accepted. Accepts any range between [0,25].
* Defaults to `1..1`.
*/
public var allowedValues: IntRange = 1..1
public var allowedValues: ClosedRange<Int> = 1..1


private var _placeholder: Optional<String> = Optional.Missing()
Expand Down Expand Up @@ -63,8 +63,8 @@ public class SelectMenuBuilder(
customId = Optional(customId),
disabled = _disabled,
placeholder = _placeholder,
minValues = OptionalInt.Value(allowedValues.first),
maxValues = OptionalInt.Value(allowedValues.last),
minValues = OptionalInt.Value(allowedValues.start),
maxValues = OptionalInt.Value(allowedValues.endInclusive),
options = Optional(options.map { it.build() })
)
}
Expand Down
8 changes: 4 additions & 4 deletions rest/src/main/kotlin/builder/component/TextInputBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class TextInputBuilder(
public var label: String,
) : ActionRowComponentBuilder() {
/**
* The range of values that can be accepted. Accepts any range between [0,4000].
* The range of lengths that can be accepted. Accepts any range between [0,4000].
*/
public var allowedLength: IntRange? = null
public var allowedLength: ClosedRange<Int>? = null

private var _placeholder: Optional<String> = Optional.Missing()

Expand Down Expand Up @@ -53,8 +53,8 @@ public class TextInputBuilder(
style = Optional(style),
customId = Optional(customId),
label = Optional(label),
minLength = allowedLength?.let { OptionalInt.Value(it.first) } ?: OptionalInt.Missing,
maxLength = allowedLength?.let { OptionalInt.Value(it.last) } ?: OptionalInt.Missing,
minLength = allowedLength?.let { OptionalInt.Value(it.start) } ?: OptionalInt.Missing,
maxLength = allowedLength?.let { OptionalInt.Value(it.endInclusive) } ?: OptionalInt.Missing,
placeholder = _placeholder,
value = _value,
required = _required,
Expand Down