diff --git a/common/src/commonMain/kotlin/entity/optional/Optional.kt b/common/src/commonMain/kotlin/entity/optional/Optional.kt index 561a6bd85e71..1e6fb7a07307 100644 --- a/common/src/commonMain/kotlin/entity/optional/Optional.kt +++ b/common/src/commonMain/kotlin/entity/optional/Optional.kt @@ -131,6 +131,11 @@ public sealed class Optional { if (value.isEmpty()) Missing() else Value(value) + public fun > Optional.missingOnEmpty(): Optional = when(this) { + is Value -> if (value.isEmpty()) Missing() else this + else -> this + } + /** * Returns a [Missing] optional of type [T]. */ diff --git a/rest/src/commonMain/kotlin/builder/interaction/EntryPointBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/EntryPointBuilders.kt index 08904a2a86a2..93fd213f9af0 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/EntryPointBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/EntryPointBuilders.kt @@ -8,6 +8,7 @@ import dev.kord.common.entity.EntryPointCommandHandlerType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.Optional.Companion.missingOnEmpty import dev.kord.common.entity.optional.delegate.delegate import dev.kord.common.entity.optional.mapList import dev.kord.rest.json.request.ApplicationCommandCreateRequest @@ -67,8 +68,8 @@ internal class EntryPointCreateBuilderImpl( state.dmPermission, @Suppress("DEPRECATION") state.defaultPermission, nsfw = state.nsfw, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), handler = Optional.Value(handler) ) } diff --git a/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt index 06f9d045ddcd..6d9fd61b02a8 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/InputChatBuilders.kt @@ -7,6 +7,7 @@ import dev.kord.common.entity.ApplicationIntegrationType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.Optional.Companion.missingOnEmpty import dev.kord.common.entity.optional.delegate.delegate import dev.kord.common.entity.optional.mapList import dev.kord.rest.json.request.ApplicationCommandCreateRequest @@ -172,8 +173,8 @@ internal class ChatInputCreateBuilderImpl( state.dmPermission, @Suppress("DEPRECATION") state.defaultPermission, nsfw = state.nsfw, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), ) } diff --git a/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt index 21c5efa80c9c..837bd8e6fa94 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/MessageCommandBuilders.kt @@ -6,6 +6,7 @@ import dev.kord.common.entity.ApplicationCommandType import dev.kord.common.entity.ApplicationIntegrationType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions +import dev.kord.common.entity.optional.Optional.Companion.missingOnEmpty import dev.kord.common.entity.optional.delegate.delegate import dev.kord.rest.json.request.ApplicationCommandCreateRequest import dev.kord.rest.json.request.ApplicationCommandModifyRequest @@ -84,8 +85,8 @@ internal class MessageCommandCreateBuilderImpl(override var name: String) : Glob defaultMemberPermissions = state.defaultMemberPermissions, defaultPermission = @Suppress("DEPRECATION") state.defaultPermission, nsfw = state.nsfw, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), ) } } diff --git a/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt b/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt index 6b8534b50fa5..86cf4c6f1e54 100644 --- a/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt +++ b/rest/src/commonMain/kotlin/builder/interaction/UserCommandBuilders.kt @@ -6,6 +6,7 @@ import dev.kord.common.entity.ApplicationCommandType import dev.kord.common.entity.ApplicationIntegrationType import dev.kord.common.entity.InteractionContextType import dev.kord.common.entity.Permissions +import dev.kord.common.entity.optional.Optional.Companion.missingOnEmpty import dev.kord.common.entity.optional.delegate.delegate import dev.kord.rest.json.request.ApplicationCommandCreateRequest import dev.kord.rest.json.request.ApplicationCommandModifyRequest @@ -79,8 +80,8 @@ internal class UserCommandCreateBuilderImpl(override var name: String) : GlobalU dmPermission = state.dmPermission, defaultPermission = @Suppress("DEPRECATION") state.defaultPermission, nsfw = state.nsfw, - integrationTypes = state.integrationTypes, - contexts = state.contexts, + integrationTypes = state.integrationTypes.missingOnEmpty(), + contexts = state.contexts.missingOnEmpty(), ) } }