From 4ecbb47bd767700b60e765a29406e6e62b2e0a6e Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Tue, 27 Aug 2024 18:33:31 +0200 Subject: [PATCH] Add support for enforceNonce (#971) * Add support for enforceNonce * Fix typo * Fix typo again --- rest/api/rest.api | 12 ++++++++---- rest/api/rest.klib.api | 10 ++++++++-- .../message/create/UserMessageCreateBuilder.kt | 12 +++++++++++- .../kotlin/json/request/MessageRequests.kt | 4 +++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/rest/api/rest.api b/rest/api/rest.api index 91bf1d6b21b..1b0fc4f685c 100644 --- a/rest/api/rest.api +++ b/rest/api/rest.api @@ -2229,10 +2229,12 @@ public final class dev/kord/rest/builder/message/create/UpdateMessageInteraction public final class dev/kord/rest/builder/message/create/UserMessageCreateBuilder : dev/kord/rest/builder/message/create/AbstractMessageCreateBuilder, dev/kord/rest/builder/RequestBuilder { public fun ()V + public final fun getEnforceNonce ()Ljava/lang/Boolean; public final fun getFailIfNotExists ()Ljava/lang/Boolean; public final fun getMessageReference ()Ldev/kord/common/entity/Snowflake; public final fun getNonce ()Ljava/lang/String; public final fun getStickerIds ()Ljava/util/List; + public final fun setEnforceNonce (Ljava/lang/Boolean;)V public final fun setFailIfNotExists (Ljava/lang/Boolean;)V public final fun setMessageReference (Ldev/kord/common/entity/Snowflake;)V public final fun setNonce (Ljava/lang/String;)V @@ -4773,10 +4775,11 @@ public final class dev/kord/rest/json/request/ListThreadsByTimestampRequest { public final class dev/kord/rest/json/request/MessageCreateRequest { public static final field Companion Ldev/kord/rest/json/request/MessageCreateRequest$Companion; public fun ()V - public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V - public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;)V + public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/optional/Optional; public final fun component10 ()Ldev/kord/common/entity/optional/Optional; + public final fun component11 ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; @@ -4785,14 +4788,15 @@ public final class dev/kord/rest/json/request/MessageCreateRequest { public final fun component7 ()Ldev/kord/common/entity/optional/Optional; public final fun component8 ()Ldev/kord/common/entity/optional/Optional; public final fun component9 ()Ldev/kord/common/entity/optional/Optional; - public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/rest/json/request/MessageCreateRequest; - public static synthetic fun copy$default (Ldev/kord/rest/json/request/MessageCreateRequest;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/rest/json/request/MessageCreateRequest; + public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;)Ldev/kord/rest/json/request/MessageCreateRequest; + public static synthetic fun copy$default (Ldev/kord/rest/json/request/MessageCreateRequest;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;ILjava/lang/Object;)Ldev/kord/rest/json/request/MessageCreateRequest; public fun equals (Ljava/lang/Object;)Z public final fun getAllowedMentions ()Ldev/kord/common/entity/optional/Optional; public final fun getAttachments ()Ldev/kord/common/entity/optional/Optional; public final fun getComponents ()Ldev/kord/common/entity/optional/Optional; public final fun getContent ()Ldev/kord/common/entity/optional/Optional; public final fun getEmbeds ()Ldev/kord/common/entity/optional/Optional; + public final fun getEnforceNonce ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun getFlags ()Ldev/kord/common/entity/optional/Optional; public final fun getMessageReference ()Ldev/kord/common/entity/optional/Optional; public final fun getNonce ()Ldev/kord/common/entity/optional/Optional; diff --git a/rest/api/rest.klib.api b/rest/api/rest.klib.api index 569a77c7fb9..5a0bc4b8049 100644 --- a/rest/api/rest.klib.api +++ b/rest/api/rest.klib.api @@ -2479,6 +2479,9 @@ final class dev.kord.rest.builder.message.create/UpdateMessageInteractionRespons final class dev.kord.rest.builder.message.create/UserMessageCreateBuilder : dev.kord.rest.builder.message.create/AbstractMessageCreateBuilder, dev.kord.rest.builder/RequestBuilder { // dev.kord.rest.builder.message.create/UserMessageCreateBuilder|null[0] constructor () // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.|(){}[0] + final var enforceNonce // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.enforceNonce|{}enforceNonce[0] + final fun (): kotlin/Boolean? // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.enforceNonce.|(){}[0] + final fun (kotlin/Boolean?) // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.enforceNonce.|(kotlin.Boolean?){}[0] final var failIfNotExists // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.failIfNotExists|{}failIfNotExists[0] final fun (): kotlin/Boolean? // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.failIfNotExists.|(){}[0] final fun (kotlin/Boolean?) // dev.kord.rest.builder.message.create/UserMessageCreateBuilder.failIfNotExists.|(kotlin.Boolean?){}[0] @@ -5197,7 +5200,7 @@ final class dev.kord.rest.json.request/ListThreadsByTimestampRequest { // dev.ko } final class dev.kord.rest.json.request/MessageCreateRequest { // dev.kord.rest.json.request/MessageCreateRequest|null[0] - constructor (dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ...) // dev.kord.rest.json.request/MessageCreateRequest.|(dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional){}[0] + constructor (dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ...) // dev.kord.rest.json.request/MessageCreateRequest.|(dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean){}[0] final val allowedMentions // dev.kord.rest.json.request/MessageCreateRequest.allowedMentions|{}allowedMentions[0] final fun (): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.allowedMentions.|(){}[0] @@ -5209,6 +5212,8 @@ final class dev.kord.rest.json.request/MessageCreateRequest { // dev.kord.rest.j final fun (): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.content.|(){}[0] final val embeds // dev.kord.rest.json.request/MessageCreateRequest.embeds|{}embeds[0] final fun (): dev.kord.common.entity.optional/Optional> // dev.kord.rest.json.request/MessageCreateRequest.embeds.|(){}[0] + final val enforceNonce // dev.kord.rest.json.request/MessageCreateRequest.enforceNonce|{}enforceNonce[0] + final fun (): dev.kord.common.entity.optional/OptionalBoolean // dev.kord.rest.json.request/MessageCreateRequest.enforceNonce.|(){}[0] final val flags // dev.kord.rest.json.request/MessageCreateRequest.flags|{}flags[0] final fun (): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.flags.|(){}[0] final val messageReference // dev.kord.rest.json.request/MessageCreateRequest.messageReference|{}messageReference[0] @@ -5222,6 +5227,7 @@ final class dev.kord.rest.json.request/MessageCreateRequest { // dev.kord.rest.j final fun component1(): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.component1|component1(){}[0] final fun component10(): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.component10|component10(){}[0] + final fun component11(): dev.kord.common.entity.optional/OptionalBoolean // dev.kord.rest.json.request/MessageCreateRequest.component11|component11(){}[0] final fun component2(): dev.kord.common.entity.optional/Optional // dev.kord.rest.json.request/MessageCreateRequest.component2|component2(){}[0] final fun component3(): dev.kord.common.entity.optional/OptionalBoolean // dev.kord.rest.json.request/MessageCreateRequest.component3|component3(){}[0] final fun component4(): dev.kord.common.entity.optional/Optional> // dev.kord.rest.json.request/MessageCreateRequest.component4|component4(){}[0] @@ -5230,7 +5236,7 @@ final class dev.kord.rest.json.request/MessageCreateRequest { // dev.kord.rest.j final fun component7(): dev.kord.common.entity.optional/Optional> // dev.kord.rest.json.request/MessageCreateRequest.component7|component7(){}[0] final fun component8(): dev.kord.common.entity.optional/Optional> // dev.kord.rest.json.request/MessageCreateRequest.component8|component8(){}[0] final fun component9(): dev.kord.common.entity.optional/Optional> // dev.kord.rest.json.request/MessageCreateRequest.component9|component9(){}[0] - final fun copy(dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ...): dev.kord.rest.json.request/MessageCreateRequest // dev.kord.rest.json.request/MessageCreateRequest.copy|copy(dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional){}[0] + final fun copy(dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional> = ..., dev.kord.common.entity.optional/Optional = ..., dev.kord.common.entity.optional/OptionalBoolean = ...): dev.kord.rest.json.request/MessageCreateRequest // dev.kord.rest.json.request/MessageCreateRequest.copy|copy(dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional>;dev.kord.common.entity.optional.Optional;dev.kord.common.entity.optional.OptionalBoolean){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // dev.kord.rest.json.request/MessageCreateRequest.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // dev.kord.rest.json.request/MessageCreateRequest.hashCode|hashCode(){}[0] final fun toString(): kotlin/String // dev.kord.rest.json.request/MessageCreateRequest.toString|toString(){}[0] diff --git a/rest/src/commonMain/kotlin/builder/message/create/UserMessageCreateBuilder.kt b/rest/src/commonMain/kotlin/builder/message/create/UserMessageCreateBuilder.kt index bd13c9ebf97..99a56168e0b 100644 --- a/rest/src/commonMain/kotlin/builder/message/create/UserMessageCreateBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/message/create/UserMessageCreateBuilder.kt @@ -8,7 +8,6 @@ import dev.kord.common.entity.optional.* import dev.kord.common.entity.optional.delegate.delegate import dev.kord.rest.builder.RequestBuilder import dev.kord.rest.builder.message.AllowedMentionsBuilder -import dev.kord.rest.builder.message.allowedMentions import dev.kord.rest.builder.message.buildMessageFlags import dev.kord.rest.json.request.MessageCreateRequest import dev.kord.rest.json.request.MultipartMessageCreateRequest @@ -25,6 +24,15 @@ public class UserMessageCreateBuilder : AbstractMessageCreateBuilder(), RequestB /** A value that can be used to verify a message was sent (up to 25 characters). */ public var nonce: String? by ::_nonce.delegate() + private var _enforceNonce: OptionalBoolean = OptionalBoolean.Missing + + /** + * If `true` and [nonce] is present, it will be checked for uniqueness in the past few minutes. + * If another message was created by the same author with the same nonce, + * that message will be returned and no new message will be created. + */ + public var enforceNonce: Boolean? by ::_enforceNonce.delegate() + private var _messageReference: OptionalSnowflake = OptionalSnowflake.Missing /** @@ -62,12 +70,14 @@ public class UserMessageCreateBuilder : AbstractMessageCreateBuilder(), RequestB messageReference = when (val id = _messageReference) { is OptionalSnowflake.Value -> Optional.Value(DiscordMessageReference(id = id, failIfNotExists = _failIfNotExists)) + is OptionalSnowflake.Missing -> Optional.Missing() }, components = _components.mapList { it.build() }, stickerIds = _stickerIds.mapCopy(), attachments = _attachments.mapList { it.toRequest() }, flags = buildMessageFlags(flags, suppressEmbeds, suppressNotifications), + enforceNonce = _enforceNonce, ), files = files.toList(), ) diff --git a/rest/src/commonMain/kotlin/json/request/MessageRequests.kt b/rest/src/commonMain/kotlin/json/request/MessageRequests.kt index f451d6da3b3..9444374bcc0 100644 --- a/rest/src/commonMain/kotlin/json/request/MessageRequests.kt +++ b/rest/src/commonMain/kotlin/json/request/MessageRequests.kt @@ -23,7 +23,9 @@ public data class MessageCreateRequest( @SerialName("sticker_ids") val stickerIds: Optional> = Optional.Missing(), val attachments: Optional> = Optional.Missing(), - val flags: Optional = Optional.Missing() + val flags: Optional = Optional.Missing(), + @SerialName("enforce_nonce") + val enforceNonce: OptionalBoolean = OptionalBoolean.Missing, ) public data class MultipartMessageCreateRequest(