diff --git a/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt index 14126c8ffb2..4bb876725fb 100644 --- a/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt +++ b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt @@ -57,6 +57,12 @@ public sealed class ApplicationCommandType( */ public object Message : ApplicationCommandType(3) + /** + * A UI-based command that represents the primary way to invoke an app's + * [Activity](https://discord.com/developers/docs/activities/overview) + */ + public object PrimaryEntryPoint : ApplicationCommandType(4) + internal object Serializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationCommandType", @@ -79,6 +85,7 @@ public sealed class ApplicationCommandType( ChatInput, User, Message, + PrimaryEntryPoint, ) } @@ -90,6 +97,7 @@ public sealed class ApplicationCommandType( 1 -> ChatInput 2 -> User 3 -> Message + 4 -> PrimaryEntryPoint else -> Unknown(value) } } diff --git a/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/EntryPointCommandHandlerType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/EntryPointCommandHandlerType.kt new file mode 100644 index 00000000000..3c05732f295 --- /dev/null +++ b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/EntryPointCommandHandlerType.kt @@ -0,0 +1,91 @@ +// 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 [EntryPointCommandHandlerType]s in the + * [Discord Developer Documentation](https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types). + */ +@Serializable(with = EntryPointCommandHandlerType.Serializer::class) +public sealed class EntryPointCommandHandlerType( + /** + * The raw value used by Discord. + */ + public val `value`: Int, +) { + final override fun equals(other: Any?): Boolean = this === other || + (other is EntryPointCommandHandlerType && this.value == other.value) + + final override fun hashCode(): Int = value.hashCode() + + final override fun toString(): String = + if (this is Unknown) "EntryPointCommandHandlerType.Unknown(value=$value)" + else "EntryPointCommandHandlerType.${this::class.simpleName}" + + /** + * An unknown [EntryPointCommandHandlerType]. + * + * This is used as a fallback for [EntryPointCommandHandlerType]s that haven't been added to + * Kord yet. + */ + public class Unknown internal constructor( + `value`: Int, + ) : EntryPointCommandHandlerType(value) + + /** + * The app handles the interaction using an interaction token + */ + public object AppHandler : EntryPointCommandHandlerType(1) + + /** + * Discord handles the interaction by launching an Activity and sending a follow-up message + * without coordinating with the app + */ + public object DiscordLaunchActivity : EntryPointCommandHandlerType(2) + + internal object Serializer : KSerializer { + override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.EntryPointCommandHandlerType", + PrimitiveKind.INT) + + override fun serialize(encoder: Encoder, `value`: EntryPointCommandHandlerType) { + encoder.encodeInt(value.value) + } + + override fun deserialize(decoder: Decoder): EntryPointCommandHandlerType = + from(decoder.decodeInt()) + } + + public companion object { + /** + * A [List] of all known [EntryPointCommandHandlerType]s. + */ + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + AppHandler, + DiscordLaunchActivity, + ) + } + + /** + * Returns an instance of [EntryPointCommandHandlerType] with + * [EntryPointCommandHandlerType.value] equal to the specified [value]. + */ + public fun from(`value`: Int): EntryPointCommandHandlerType = when (value) { + 1 -> AppHandler + 2 -> DiscordLaunchActivity + else -> Unknown(value) + } + } +} diff --git a/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt index e5bdb7de060..3fe28deb5a9 100644 --- a/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt +++ b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt @@ -79,6 +79,11 @@ public sealed class InteractionResponseType( */ public object Modal : InteractionResponseType(9) + /** + * Launch the Activity associated with the app. Only available for apps with Activities enabled + */ + public object LaunchActivity : InteractionResponseType(12) + internal object Serializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionResponseType", @@ -105,6 +110,7 @@ public sealed class InteractionResponseType( UpdateMessage, ApplicationCommandAutoCompleteResult, Modal, + LaunchActivity, ) } @@ -120,6 +126,7 @@ public sealed class InteractionResponseType( 7 -> UpdateMessage 8 -> ApplicationCommandAutoCompleteResult 9 -> Modal + 12 -> LaunchActivity else -> Unknown(type) } } diff --git a/common/src/commonMain/kotlin/entity/Interactions.kt b/common/src/commonMain/kotlin/entity/Interactions.kt index 209cdecc9a2..562d26f0960 100644 --- a/common/src/commonMain/kotlin/entity/Interactions.kt +++ b/common/src/commonMain/kotlin/entity/Interactions.kt @@ -8,9 +8,25 @@ "Message", intValue = 3, kDoc = "A UI-based command that shows up when you right-click or tap on a message.", ), + Entry( + "PrimaryEntryPoint", intValue = 4, + kDoc = "A UI-based command that represents the primary way to invoke an app's [Activity](https://discord.com/developers/docs/activities/overview)" + ) ], ) +@file:Generate( + INT_KORD_ENUM, name = "EntryPointCommandHandlerType", + docUrl = "https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types", + entries = [ + Entry("AppHandler", intValue = 1, kDoc = "The app handles the interaction using an interaction token"), + Entry( + "DiscordLaunchActivity", intValue = 2, + kDoc = "Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with the app" + ) + ] +) + @file:Generate( INT_KORD_ENUM, name = "ApplicationCommandOptionType", valueName = "type", docUrl = "https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type", @@ -62,6 +78,7 @@ kDoc = "Respond to an autocomplete interaction with suggested choices.", ), Entry("Modal", intValue = 9, kDoc = "Respond to an interaction with a popup modal."), + Entry("LaunchActivity", intValue = 12, kDoc = "\tLaunch the Activity associated with the app. Only available for apps with Activities enabled") ], ) diff --git a/core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt index cea8e6d296f..a5c43db3a47 100644 --- a/core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt +++ b/core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt @@ -1,5 +1,6 @@ package dev.kord.core.behavior.interaction.response +import dev.kord.common.entity.InteractionResponseType import dev.kord.common.entity.Snowflake import dev.kord.core.KordObject import dev.kord.core.entity.Strategizable @@ -7,6 +8,7 @@ import dev.kord.core.entity.interaction.Interaction import dev.kord.core.entity.interaction.followup.FollowupMessage import dev.kord.core.exception.EntityNotFoundException import dev.kord.core.supplier.EntitySupplyStrategy +import dev.kord.rest.json.request.InteractionResponseCreateRequest import dev.kord.rest.request.RestRequestException /** @@ -44,5 +46,16 @@ public sealed interface InteractionResponseBehavior : KordObject, Strategizable public suspend fun getFollowupMessage(messageId: Snowflake): FollowupMessage = supplier.getFollowupMessage(applicationId, token, messageId) + /** + * Opens the [Activity](https://discord.com/developers/docs/activities/overview) of this application. + * **Note:** This requires activities to be enabled for this application + */ + public suspend fun openActivity() { + kord.rest.interaction.createInteractionResponse( + applicationId, token, + InteractionResponseCreateRequest(InteractionResponseType.LaunchActivity) + ) + } + override fun withStrategy(strategy: EntitySupplyStrategy<*>): InteractionResponseBehavior }