Skip to content

Commit

Permalink
Add support for User installable apps
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 25, 2024
1 parent a4311db commit a673908
Show file tree
Hide file tree
Showing 30 changed files with 1,194 additions and 202 deletions.
216 changes: 167 additions & 49 deletions common/api/common.api

Large diffs are not rendered by default.

235 changes: 181 additions & 54 deletions common/api/common.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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

/**
* Where an app can be installed, also called its supported installation contexts
*
* See [ApplicationIntegrationType]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/application#application-object-application-integration-types).
*/
@Serializable(with = ApplicationIntegrationType.Serializer::class)
public sealed class ApplicationIntegrationType(
/**
* The raw value used by Discord.
*/
public val `value`: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is ApplicationIntegrationType && this.value == other.value)

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

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

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

/**
* App is installable to servers
*/
public object GuildInstall : ApplicationIntegrationType(0)

/**
* App is installable to users
*/
public object UserInstall : ApplicationIntegrationType(0)

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

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

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

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

/**
* Returns an instance of [ApplicationIntegrationType] with
* [ApplicationIntegrationType.value] equal to the specified [value].
*/
public fun from(`value`: Int): ApplicationIntegrationType = when (value) {
0 -> GuildInstall
else -> Unknown(value)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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

/**
* Context in Discord where an interaction can be used, or where it was triggered from.
*
* 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 value used by Discord.
*/
public val `value`: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is InteractionContextType && this.value == other.value)

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

final override fun toString(): String =
if (this is Unknown) "InteractionContextType.Unknown(value=$value)"
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(
`value`: Int,
) : InteractionContextType(value)

/**
* Interaction can be used within servers
*/
public object Guild : InteractionContextType(0)

/**
* Interaction can be used within DMs with the app's bot user
*/
public object BotDM : InteractionContextType(1)

/**
* Interaction can be used within Group DMs and DMs other than the app's bot user
*/
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.value)
}

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.value] equal
* to the specified [value].
*/
public fun from(`value`: Int): InteractionContextType = when (value) {
0 -> Guild
1 -> BotDM
2 -> PrivateChannel
else -> Unknown(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ public sealed class Permission(
*/
public object SendVoiceMessages : Permission(46)

/**
* Allows user-installed apps to send public responses. When disabled, users will still be
* allowed to use their apps but the responses will be ephemeral. This only applies to apps not
* also installed to the server.
*/
public object USE_EXTERNAL_APPS : Permission(50)

public companion object {
/**
* A [List] of all known [Permission]s.
Expand Down Expand Up @@ -365,6 +372,7 @@ public sealed class Permission(
CreateEvents,
UseExternalSounds,
SendVoiceMessages,
USE_EXTERNAL_APPS,
)
}

Expand Down Expand Up @@ -422,6 +430,7 @@ public sealed class Permission(
44 -> CreateEvents
45 -> UseExternalSounds
46 -> SendVoiceMessages
50 -> USE_EXTERNAL_APPS
else -> Unknown(shift)
}
}
Expand Down
4 changes: 4 additions & 0 deletions common/src/commonMain/kotlin/entity/DiscordApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public data class DiscordApplication(
val botPublic: Boolean,
@SerialName("bot_require_code_grant")
val botRequireCodeGrant: Boolean,
val bot: Optional<DiscordUser> = Optional.Missing(),
@SerialName("terms_of_service_url")
override val termsOfServiceUrl: Optional<String> = Optional.Missing(),
@SerialName("privacy_policy_url")
Expand All @@ -111,6 +112,7 @@ public data class DiscordApplication(
val team: DiscordTeam?,
@SerialName("guild_id")
override val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
val guild: Optional<DiscordPartialGuild> = Optional.Missing(),
@SerialName("primary_sku_id")
override val primarySkuId: OptionalSnowflake = OptionalSnowflake.Missing,
override val slug: Optional<String> = Optional.Missing(),
Expand All @@ -120,6 +122,8 @@ public data class DiscordApplication(
override val tags: Optional<List<String>> = Optional.Missing(),
@SerialName("install_params")
override val installParams: Optional<InstallParams> = Optional.Missing(),
@SerialName("integration_types_config")
val integrationTypesConfig: Optional<Map<ApplicationIntegrationType, InstallParams>> = Optional.Missing(),
@SerialName("custom_install_url")
override val customInstallUrl: Optional<String> = Optional.Missing(),
@SerialName("role_connections_verification_url")
Expand Down
11 changes: 10 additions & 1 deletion common/src/commonMain/kotlin/entity/DiscordIntegration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
],
)

@file:Generate(
INT_KORD_ENUM, name = "ApplicationIntegrationType",
docUrl = "https://discord.com/developers/docs/resources/application#application-object-application-integration-types",
kDoc = "Where an app can be installed, also called its supported installation contexts",
entries = [
Entry("GuildInstall", intValue = 0, kDoc = "App is installable to servers"),
Entry("UserInstall", intValue = 0, kDoc = "App is installable to users"),
],
)

package dev.kord.common.entity

import dev.kord.common.entity.optional.Optional
Expand All @@ -27,7 +37,6 @@ public data class DiscordIntegration(
val name: String,
val type: String,
val enabled: Boolean,
val syncing: OptionalBoolean = OptionalBoolean.Missing,
@SerialName("role_id")
val roleId: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("enable_emoticons")
Expand Down
30 changes: 30 additions & 0 deletions common/src/commonMain/kotlin/entity/DiscordMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,39 @@ public data class DiscordMessage(
* This is a list even though the docs say it's a component
*/
val components: Optional<List<DiscordComponent>> = Optional.Missing(),
val interactionMetadata: Optional<DiscordInteractionMetadata> = Optional.Missing(),
@Deprecated("Deprecated in favor of interactionMetadata", ReplaceWith("interactionMetadata"))
val interaction: Optional<DiscordMessageInteraction> = Optional.Missing(),
val thread: Optional<DiscordChannel> = Optional.Missing(),
val position: OptionalInt = OptionalInt.Missing
)

/**
* Metadata about the interaction, including the source of the interaction and relevant server and user IDs.
*
* @property id The ID of the interaction.
* @property type The type of the interaction.
* @property user The user associated with the interaction.
* @property authorizingIntegrationOwners IDs for installation context(s) related to an interaction
* @property originalResponseMessageId ID of the original response message, present only on follow-up messages
* @property interactedMessageId ID of the message that contained interactive component, present only on messages created from component interactions
* @property triggeringInteractionMetadata Metadata for the interaction that was used to open the modal, present only on modal submit interactions
*/
@Serializable
public data class DiscordInteractionMetadata(
val id: Snowflake,
val type: InteractionType,
val user: DiscordUser,
@SerialName("authorizing_integration_owners")
val authorizingIntegrationOwners: IntegrationOwners,
@SerialName("original_response_message_id")
val originalResponseMessageId: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("interacted_message_id")
val interactedMessageId: OptionalSnowflake = OptionalSnowflake.Missing,
@SerialName("triggering_interaction_metadata")
val triggeringInteractionMetadata: Optional<DiscordInteractionMetadata> = Optional.Missing()
)

/**
* @param id id of the sticker
* @param packId id of the pack the sticker is from
Expand Down Expand Up @@ -370,6 +398,8 @@ public data class DiscordPartialMessage(
val stickers: Optional<List<DiscordStickerItem>> = Optional.Missing(),
@SerialName("referenced_message")
val referencedMessage: Optional<DiscordMessage?> = Optional.Missing(),
val interactionMetadata: Optional<DiscordInteractionMetadata> = Optional.Missing(),
@Deprecated("Deprecated in favor of interactionMetadata")
val interaction: Optional<DiscordMessageInteraction> = Optional.Missing(),
val position: OptionalInt = OptionalInt.Missing,
)
Expand Down
Loading

0 comments on commit a673908

Please sign in to comment.