-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* acknowledgement message flags * don't forget return types * allow modifying flags in interaction responses * add a overloaded acknowledgement * update docs * overload InteractionBehavior#acknowledge to accept list of flags * update InteractionBehavior#respond docs and params * introduce public and ephemeral responses * remove unresolved classes * inline InteractionResponseBehaviors edit functions * Optionalize builder in ephemeral responds * introduce PublicFollowupMessage and EphemeralFollowupMessage * restructure interaction behaviors/builders/entities * Fix follow up and allowedMentions builders * Ephemeral defer + Followup returns an ephemeral followup * Fix typing and support multipart public response creation * Rewrite builders * rewrite behaviors * wait flag is always true for followups * Add channel behavior * Document public/ephemeral followup message and interaction responses * Apply suggestions Co-authored-by: Bart Arys <[email protected]> * Fix imports * implement Strategizable interface * apply suggestions Co-authored-by: Bart Arys <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,117 additions
and
579 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
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
core/src/main/kotlin/behavior/InteractionFollowupBehavior.kt
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
core/src/main/kotlin/behavior/InteractionResponseBehavior.kt
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
core/src/main/kotlin/behavior/interaction/EphemeralFollowupMessageBehavior.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,68 @@ | ||
package dev.kord.core.behavior.interaction | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.cache.data.toData | ||
import dev.kord.core.entity.Message | ||
import dev.kord.core.entity.interaction.EphemeralFollowupMessage | ||
import dev.kord.core.entity.interaction.PublicFollowupMessage | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
import dev.kord.rest.builder.interaction.EphemeralFollowupMessageModifyBuilder | ||
import dev.kord.rest.request.RestRequestException | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
/** | ||
* The behavior of a [Discord Followup Message](https://discord.com/developers/docs/interactions/slash-commands#followup-messages) | ||
* This followup message is visible to *only* to the user who made the interaction. | ||
*/ | ||
@KordPreview | ||
interface EphemeralFollowupMessageBehavior : FollowupMessageBehavior { | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): EphemeralFollowupMessageBehavior { | ||
return EphemeralFollowupMessageBehavior(id, applicationId, token ,channelId, kord, strategy.supply(kord)) | ||
} | ||
} | ||
|
||
/** | ||
* Requests to edit this followup message. | ||
* | ||
* @return The edited [PublicFollowupMessage] of the interaction response. | ||
* | ||
* @throws [RestRequestException] if something went wrong during the request. | ||
*/ | ||
@KordPreview | ||
@OptIn(ExperimentalContracts::class) | ||
suspend inline fun EphemeralFollowupMessageBehavior.edit(builder: EphemeralFollowupMessageModifyBuilder.() -> Unit): EphemeralFollowupMessage { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val builder = EphemeralFollowupMessageModifyBuilder().apply(builder) | ||
val response = kord.rest.interaction.modifyFollowupMessage(applicationId, token, id, builder.toRequest()) | ||
return EphemeralFollowupMessage(Message(response.toData(), kord), applicationId, token, kord) | ||
} | ||
|
||
@KordPreview | ||
fun EphemeralFollowupMessageBehavior( | ||
id: Snowflake, | ||
applicationId: Snowflake, | ||
token: String, | ||
channelId: Snowflake, | ||
kord: Kord, | ||
supplier: EntitySupplier | ||
): EphemeralFollowupMessageBehavior = object : EphemeralFollowupMessageBehavior { | ||
override val applicationId: Snowflake | ||
get() = applicationId | ||
override val token: String | ||
get() = token | ||
override val channelId: Snowflake | ||
get() = channelId | ||
override val kord: Kord | ||
get() = kord | ||
override val id: Snowflake | ||
get() = id | ||
override val supplier: EntitySupplier | ||
get() = supplier | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
core/src/main/kotlin/behavior/interaction/EphemeralInteractionResponseBehavior.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,92 @@ | ||
package dev.kord.core.behavior.interaction | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.annotation.KordUnsafe | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.cache.data.toData | ||
import dev.kord.core.entity.Message | ||
import dev.kord.core.entity.interaction.EphemeralFollowupMessage | ||
import dev.kord.core.entity.interaction.PublicFollowupMessage | ||
import dev.kord.rest.builder.interaction.EphemeralFollowupMessageCreateBuilder | ||
import dev.kord.rest.builder.interaction.EphemeralInteractionResponseModifyBuilder | ||
import dev.kord.rest.builder.interaction.PublicFollowupMessageCreateBuilder | ||
import dev.kord.rest.request.RestRequestException | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
/** | ||
* The behavior of a ephemeral [Discord Interaction Response](https://discord.com/developers/docs/interactions/slash-commands#interaction-response) | ||
* This response is visible to *only* to the user who made the interaction. | ||
*/ | ||
@KordPreview | ||
interface EphemeralInteractionResponseBehavior : InteractionResponseBehavior | ||
|
||
/** | ||
* Requests to edit this interaction response. | ||
* | ||
* @return The edited [Message] of the interaction response. | ||
* | ||
* @throws [RestRequestException] if something went wrong during the request. | ||
*/ | ||
@KordPreview | ||
@OptIn(ExperimentalContracts::class) | ||
suspend inline fun EphemeralInteractionResponseBehavior.edit(builder: EphemeralInteractionResponseModifyBuilder.() -> Unit) { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val builder = EphemeralInteractionResponseModifyBuilder().apply(builder) | ||
kord.rest.interaction.modifyInteractionResponse(applicationId, token, builder.toRequest()) | ||
} | ||
|
||
/** | ||
* Follows-up this interaction response with a [EphemeralFollowupMessage] | ||
* | ||
* @return created [EphemeralFollowupMessage] | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
@KordPreview | ||
suspend inline fun EphemeralInteractionResponseBehavior.followUp( | ||
content: String, | ||
builder: EphemeralFollowupMessageCreateBuilder.() -> Unit = {} | ||
): EphemeralFollowupMessage { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val builder = EphemeralFollowupMessageCreateBuilder(content).apply(builder) | ||
val response = kord.rest.interaction.createFollowupMessage(applicationId, token, builder.toRequest()) | ||
val message = Message(response.toData(), kord) | ||
return EphemeralFollowupMessage(message, applicationId, token, kord) | ||
} | ||
|
||
|
||
/** | ||
* Follows-up this interaction response with a [PublicFollowupMessage] | ||
* | ||
* This function assumes that this interaction response has content in it. | ||
* Use [the safe method overload][EphemeralInteractionResponseBehavior.followUp] if you are unsure | ||
* | ||
* @return created [PublicFollowupMessage] | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
@KordPreview | ||
@KordUnsafe | ||
suspend inline fun EphemeralInteractionResponseBehavior.followUp( | ||
builder: PublicFollowupMessageCreateBuilder.() -> Unit | ||
): PublicFollowupMessage { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val builder = PublicFollowupMessageCreateBuilder().apply(builder) | ||
val response = kord.rest.interaction.createFollowupMessage(applicationId, token, builder.toRequest()) | ||
val message = Message(response.toData(), kord) | ||
return PublicFollowupMessage(message, applicationId, token, kord) | ||
} | ||
|
||
@KordPreview | ||
fun EphemeralInteractionResponseBehavior(applicationId: Snowflake, token: String, kord: Kord): EphemeralInteractionResponseBehavior = | ||
object : EphemeralInteractionResponseBehavior { | ||
override val applicationId: Snowflake | ||
get() = applicationId | ||
|
||
override val token: String | ||
get() = token | ||
|
||
override val kord: Kord | ||
get() = kord | ||
} |
Oops, something went wrong.