Skip to content
Open
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
@@ -0,0 +1,87 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

package dev.kord.common.entity

import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [InteractionContextType]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types).
*/
@Serializable(with = InteractionContextType.Serializer::class)
public sealed class InteractionContextType(
/**
* The raw type used by Discord.
*/
public val type: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is InteractionContextType && this.type == other.type)

final override fun hashCode(): Int = type.hashCode()

final override fun toString(): String =
if (this is Unknown) "InteractionContextType.Unknown(type=$type)"
else "InteractionContextType.${this::class.simpleName}"

/**
* An unknown [InteractionContextType].
*
* This is used as a fallback for [InteractionContextType]s that haven't been added to Kord yet.
*/
public class Unknown internal constructor(
type: Int,
) : InteractionContextType(type)

public object Guild : InteractionContextType(0)

public object BotDm : InteractionContextType(1)

public object PrivateChannel : InteractionContextType(2)

internal object Serializer : KSerializer<InteractionContextType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionContextType",
PrimitiveKind.INT)

override fun serialize(encoder: Encoder, `value`: InteractionContextType) {
encoder.encodeInt(value.type)
}

override fun deserialize(decoder: Decoder): InteractionContextType =
from(decoder.decodeInt())
}

public companion object {
/**
* A [List] of all known [InteractionContextType]s.
*/
public val entries: List<InteractionContextType> by lazy(mode = PUBLICATION) {
listOf(
Guild,
BotDm,
PrivateChannel,
)
}

/**
* Returns an instance of [InteractionContextType] with [InteractionContextType.type] equal
* to the specified [type].
*/
public fun from(type: Int): InteractionContextType = when (type) {
0 -> Guild
1 -> BotDm
2 -> PrivateChannel
else -> Unknown(type)
}
}
}
13 changes: 13 additions & 0 deletions common/src/commonMain/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@
],
)

@file:Generate(
INT_KORD_ENUM, name = "InteractionContextType", valueName = "type",
docUrl = "https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-context-types",
entries = [
Entry("Guild", intValue = 0),
Entry("BotDm", intValue = 1),
Entry("PrivateChannel", intValue = 2),
]
)

package dev.kord.common.entity

import dev.kord.common.Locale
Expand Down Expand Up @@ -113,7 +123,9 @@ public data class DiscordApplicationCommand(
@SerialName("default_member_permissions")
val defaultMemberPermissions: Permissions?,
@SerialName("dm_permission")
@Deprecated("'dm_permission' is deprecated in favor of 'contexts'.")
val dmPermission: OptionalBoolean = OptionalBoolean.Missing,
val contexts: Optional<List<InteractionContextType>> = Optional.Missing(),
@SerialName("default_permission")
@Deprecated("'defaultPermission' is deprecated in favor of 'defaultMemberPermissions' and 'dmPermission'.")
val defaultPermission: OptionalBoolean? = OptionalBoolean.Missing,
Expand Down Expand Up @@ -262,6 +274,7 @@ public data class DiscordInteraction(
val guildLocale: Optional<Locale> = Optional.Missing(),
// Don't trust the docs: This can be missing
val entitlements: Optional<List<DiscordEntitlement>> = Optional.Missing(),
val context: Optional<InteractionContextType> = Optional.Missing(),
) {

/**
Expand Down
3 changes: 3 additions & 0 deletions common/src/commonTest/kotlin/json/InteractionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class InteractionTest {
arg.value shouldBe 1L
appPermissions shouldBe perms
entitlements shouldBe testEntitlements
context shouldBe InteractionContextType.Guild
}
}

Expand Down Expand Up @@ -115,6 +116,7 @@ class InteractionTest {
arg.value shouldBe 1L
appPermissions shouldBe perms
entitlements shouldBe testEntitlements
context shouldBe InteractionContextType.BotDm
}
}

Expand Down Expand Up @@ -156,6 +158,7 @@ class InteractionTest {
id shouldBe "847587388497854464"
appPermissions shouldBe perms
entitlements shouldBe testEntitlements
context shouldBe InteractionContextType.PrivateChannel
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
"type":8,
"deleted":false
}
]
],
"context": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
"type":8,
"deleted":false
}
]
],
"context": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
"type":8,
"deleted":false
}
]
],
"context": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public data class ApplicationCommandData(
val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
val options: Optional<List<ApplicationCommandOptionData>> = Optional.Missing(),
val defaultMemberPermissions: Permissions?,
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
val dmPermission: OptionalBoolean = OptionalBoolean.Missing,
val contexts: Optional<List<InteractionContextType>> = Optional.Missing(),
@Deprecated("'defaultPermission' is deprecated in favor of 'defaultMemberPermissions' and 'dmPermission'.")
val defaultPermission: OptionalBoolean? = OptionalBoolean.Missing,
val nsfw: OptionalBoolean = OptionalBoolean.Missing,
Expand All @@ -45,7 +47,8 @@ public data class ApplicationCommandData(
guildId,
options.mapList { ApplicationCommandOptionData.from(it) },
defaultMemberPermissions,
dmPermission,
@Suppress("DEPRECATION") dmPermission,
contexts,
@Suppress("DEPRECATION") defaultPermission,
nsfw,
version
Expand Down
2 changes: 2 additions & 0 deletions core/src/commonMain/kotlin/cache/data/InteractionData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public data class InteractionData(
val locale: Optional<Locale> = Optional.Missing(),
val guildLocale: Optional<Locale> = Optional.Missing(),
val entitlements: Optional<List<EntitlementData>> = Optional.Missing(),
val context: Optional<InteractionContextType> = Optional.Missing(),
) {
public companion object {
public fun from(interaction: DiscordInteraction): InteractionData {
Expand All @@ -55,6 +56,7 @@ public data class InteractionData(
locale,
guildLocale,
entitlements.mapList { EntitlementData.from(it) },
context,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.kord.core.entity.application
import dev.kord.common.Locale
import dev.kord.common.entity.ApplicationCommandType
import dev.kord.common.entity.ChannelType
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.Permissions
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.orEmpty
Expand Down Expand Up @@ -68,7 +69,14 @@ public interface GlobalApplicationCommand : ApplicationCommand, GlobalApplicatio
/**
* Whether this command is available in DMs with the application.
*/
public val dmPermission: Boolean get() = data.dmPermission.orElse(true)
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
public val dmPermission: Boolean get() = @Suppress("DEPRECATION") data.dmPermission.orElse(true)

/**
* Interaction context(s) where the command can be used.
*/
public val contexts: List<InteractionContextType>? get() = data.contexts.value
}
public class UnknownGlobalApplicationCommand(
override val data: ApplicationCommandData,
Expand Down
6 changes: 6 additions & 0 deletions core/src/commonMain/kotlin/entity/interaction/Interaction.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.core.entity.interaction

import dev.kord.common.Locale
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.InteractionType
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.OptionalSnowflake
Expand Down Expand Up @@ -63,6 +64,11 @@ public sealed interface Interaction : InteractionBehavior {
*/
public val entitlements: List<Entitlement> get() = data.entitlements.mapList { Entitlement(it, kord) }.orEmpty()

/**
* Context where the interaction was triggered from
*/
public val context: InteractionContextType? get() = data.context.value

override fun withStrategy(strategy: EntitySupplyStrategy<*>): Interaction

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.kord.rest.builder.interaction

import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.ApplicationCommandType
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.Permissions
import dev.kord.rest.builder.RequestBuilder
import dev.kord.rest.json.request.ApplicationCommandCreateRequest
Expand Down Expand Up @@ -32,12 +33,16 @@ public interface ApplicationCommandCreateBuilder : LocalizedNameCreateBuilder,

@KordDsl
public interface GlobalApplicationCommandCreateBuilder : ApplicationCommandCreateBuilder {
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
public var dmPermission: Boolean?
public var contexts: MutableList<InteractionContextType>?
}

@KordDsl
public interface GlobalApplicationCommandModifyBuilder : ApplicationCommandModifyBuilder {
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
public var dmPermission: Boolean?
public var contexts: MutableList<InteractionContextType>?
}

@KordDsl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.rest.builder.interaction

import dev.kord.common.Locale
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.OptionalBoolean
Expand All @@ -22,8 +23,9 @@ internal class ApplicationCommandModifyStateHolder {
var options: Optional<MutableList<OptionsBuilder>> = Optional.Missing()

var defaultMemberPermissions: Optional<Permissions?> = Optional.Missing()
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
var dmPermission: OptionalBoolean? = OptionalBoolean.Missing

var contexts: Optional<MutableList<InteractionContextType>> = Optional.Missing()

@Deprecated("'defaultPermission' is deprecated in favor of 'defaultMemberPermissions' and 'dmPermission'. Setting 'defaultPermission' to false can be replaced by setting 'defaultMemberPermissions' to empty Permissions and 'dmPermission' to false ('dmPermission' is only available for global commands).")
@SerialName("default_permission")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.kord.rest.builder.interaction
import dev.kord.common.Locale
import dev.kord.common.annotation.KordDsl
import dev.kord.common.entity.ApplicationCommandType
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.delegate.delegate
Expand Down Expand Up @@ -147,7 +148,9 @@ internal class ChatInputCreateBuilderImpl(

override var options: MutableList<OptionsBuilder>? by state::options.delegate()
override var defaultMemberPermissions: Permissions? by state::defaultMemberPermissions.delegate()
override var dmPermission: Boolean? by state::dmPermission.delegate()
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
override var dmPermission: Boolean? by @Suppress("DEPRECATION") state::dmPermission.delegate()
override var contexts: MutableList<InteractionContextType>? by state::contexts.delegate()

@Deprecated("'defaultPermission' is deprecated in favor of 'defaultMemberPermissions' and 'dmPermission'. Setting 'defaultPermission' to false can be replaced by setting 'defaultMemberPermissions' to empty Permissions and 'dmPermission' to false ('dmPermission' is only available for global commands).")
override var defaultPermission: Boolean? by @Suppress("DEPRECATION") state::defaultPermission.delegate()
Expand All @@ -163,7 +166,8 @@ internal class ChatInputCreateBuilderImpl(
state.descriptionLocalizations,
state.options.mapList { it.toRequest() },
state.defaultMemberPermissions,
state.dmPermission,
@Suppress("DEPRECATION") state.dmPermission,
state.contexts,
@Suppress("DEPRECATION") state.defaultPermission,
nsfw = state.nsfw,
)
Expand Down Expand Up @@ -192,7 +196,9 @@ internal class ChatInputModifyBuilderImpl : GlobalChatInputModifyBuilder {
override var options: MutableList<OptionsBuilder>? by state::options.delegate()

override var defaultMemberPermissions: Permissions? by state::defaultMemberPermissions.delegate()
override var dmPermission: Boolean? by state::dmPermission.delegate()
@Deprecated("'dmPermission' is deprecated in favor of 'contexts'.")
override var dmPermission: Boolean? by @Suppress("DEPRECATION") state::dmPermission.delegate()
override var contexts: MutableList<InteractionContextType>? by state::contexts.delegate()

@Deprecated("'defaultPermission' is deprecated in favor of 'defaultMemberPermissions' and 'dmPermission'. Setting 'defaultPermission' to false can be replaced by setting 'defaultMemberPermissions' to empty Permissions and 'dmPermission' to false ('dmPermission' is only available for global commands).")
override var defaultPermission: Boolean? by @Suppress("DEPRECATION") state::defaultPermission.delegate()
Expand All @@ -207,7 +213,8 @@ internal class ChatInputModifyBuilderImpl : GlobalChatInputModifyBuilder {
state.descriptionLocalizations,
state.options.mapList { it.toRequest() },
state.defaultMemberPermissions,
state.dmPermission,
@Suppress("DEPRECATION") state.dmPermission,
state.contexts,
@Suppress("DEPRECATION") state.defaultPermission,
nsfw = state.nsfw,
)
Expand Down
Loading