Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for User installable apps #970

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a673908
Add support for User installable apps
DRSchlaubi Aug 25, 2024
d567e98
Fix failing tests
DRSchlaubi Aug 25, 2024
366a1a7
Make contexts nullable
DRSchlaubi Aug 25, 2024
041a405
Add count approximations
DRSchlaubi Aug 25, 2024
97594ea
Fix Serialization of interactions
DRSchlaubi Aug 25, 2024
60548fc
Fix Invalid serialization of ApplicationIntegrationType
DRSchlaubi Aug 25, 2024
7182288
Fix serialization of DiscordApplication.kt
DRSchlaubi Sep 25, 2024
17ec83f
Merge remote-tracking branch 'origin/main' into feature/user-apps
DRSchlaubi Sep 25, 2024
61206ea
Optimize imports
DRSchlaubi Sep 25, 2024
067082e
Fix compiler error
DRSchlaubi Sep 25, 2024
a6a8e6d
Merge remote-tracking branch 'origin/main' into feature/user-apps
DRSchlaubi Oct 22, 2024
5e242fa
Add initial draft for entry point commands
DRSchlaubi Oct 22, 2024
27545a1
Finalize entry point command stuff
DRSchlaubi Oct 22, 2024
839e47d
Api dump
DRSchlaubi Oct 22, 2024
fcf88c2
Fix registration of commands
DRSchlaubi Oct 24, 2024
0436913
Api dump
DRSchlaubi Oct 25, 2024
718206c
Move openActivity to the correct interface
DRSchlaubi Oct 25, 2024
35862e8
Api dump
DRSchlaubi Oct 25, 2024
3ac3ec7
Add contexts and integrationTypes to modify builders
DRSchlaubi Oct 27, 2024
12848e8
Fix openActivity causing 404 error
DRSchlaubi Oct 27, 2024
5c6ed1d
Add ability to receive
DRSchlaubi Oct 27, 2024
5fb4587
Unify names
DRSchlaubi Oct 27, 2024
17caabb
Api dump
DRSchlaubi Oct 27, 2024
ceea3d7
Merge remote-tracking branch 'origin/main' into feature/user-apps
DRSchlaubi Nov 2, 2024
8660e92
Fix Serialization issue
DRSchlaubi Nov 6, 2024
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
319 changes: 268 additions & 51 deletions common/api/common.api

Large diffs are not rendered by default.

331 changes: 275 additions & 56 deletions common/api/common.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationCommandType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationCommandType",
Expand All @@ -79,6 +85,7 @@ public sealed class ApplicationCommandType(
ChatInput,
User,
Message,
PrimaryEntryPoint,
)
}

Expand All @@ -90,6 +97,7 @@ public sealed class ApplicationCommandType(
1 -> ChatInput
2 -> User
3 -> Message
4 -> PrimaryEntryPoint
else -> Unknown(value)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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(1)

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,
UserInstall,
)
}

/**
* Returns an instance of [ApplicationIntegrationType] with
* [ApplicationIntegrationType.value] equal to the specified [value].
*/
public fun from(`value`: Int): ApplicationIntegrationType = when (value) {
0 -> GuildInstall
1 -> UserInstall
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 @@ -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<InteractionResponseType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionResponseType",
Expand All @@ -105,6 +110,7 @@ public sealed class InteractionResponseType(
UpdateMessage,
ApplicationCommandAutoCompleteResult,
Modal,
LaunchActivity,
)
}

Expand All @@ -120,6 +126,7 @@ public sealed class InteractionResponseType(
7 -> UpdateMessage
8 -> ApplicationCommandAutoCompleteResult
9 -> Modal
12 -> LaunchActivity
else -> Unknown(type)
}
}
Expand Down
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
Original file line number Diff line number Diff line change
@@ -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 [PrimaryEntryPointCommandHandlerType]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types).
*/
@Serializable(with = PrimaryEntryPointCommandHandlerType.Serializer::class)
public sealed class PrimaryEntryPointCommandHandlerType(
/**
* The raw value used by Discord.
*/
public val `value`: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is PrimaryEntryPointCommandHandlerType && this.value == other.value)

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

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

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

/**
* The app handles the interaction using an interaction token
*/
public object AppHandler : PrimaryEntryPointCommandHandlerType(1)

/**
* Discord handles the interaction by launching an Activity and sending a follow-up message
* without coordinating with the app
*/
public object DiscordLaunchActivity : PrimaryEntryPointCommandHandlerType(2)

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

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

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

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

/**
* Returns an instance of [PrimaryEntryPointCommandHandlerType] with
* [PrimaryEntryPointCommandHandlerType.value] equal to the specified [value].
*/
public fun from(`value`: Int): PrimaryEntryPointCommandHandlerType = when (value) {
1 -> AppHandler
2 -> DiscordLaunchActivity
else -> Unknown(value)
}
}
}
Loading