Skip to content

Commit

Permalink
Fix registration of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 24, 2024
1 parent 839e47d commit fcf88c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions common/src/commonMain/kotlin/entity/optional/Optional.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public sealed class Optional<out T> {
if (value.isEmpty()) Missing()
else Value(value)

public fun <T, C : Collection<T>> Optional<C>.missingOnEmpty(): Optional<C> = when(this) {
is Value -> if (value.isEmpty()) Missing() else this
else -> this
}

/**
* Returns a [Missing] optional of type [T].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)
}
}

0 comments on commit fcf88c2

Please sign in to comment.