diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ecb35fd6cd..ece57b24d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +# 0.7.3 + +## Additions + +* Add StoreEntitySupplier. +* Add caching rest strategy. +* Add cache-rest caching strategy. +* Add select menus. + +## Fixes + +* Fix average ping conversion in `MasterGateway`. + +## Changes + +* Make `UpdateMessageInteractionResponseCreateBuilder` fields nullable. +* type in option builders is now private + +## Breaking + +* DiscordComponent +* InteractionCallbackData +* ApplicationInteractionData +* ComponentData +* CommandInteraction +* OptionsBuilder +* UpdateMessageInteractionResponseCreateBuilder + + # 0.7.2 ## Additions @@ -11,7 +40,7 @@ ## Fixes * Mentionable arguments now correctly retrieve their entity. -* `Intent#values` emitting null when filtering. +* `Intent.values` emitting null when filtering. # 0.7.1 diff --git a/common/api/common.api b/common/api/common.api index 7fba328e126..6d01d5df98d 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -962,6 +962,10 @@ public final class dev/kord/common/entity/ComponentType$Button : dev/kord/common public static final field INSTANCE Ldev/kord/common/entity/ComponentType$Button; } +public final class dev/kord/common/entity/ComponentType$SelectMenu : dev/kord/common/entity/ComponentType { + public static final field INSTANCE Ldev/kord/common/entity/ComponentType$SelectMenu; +} + public final class dev/kord/common/entity/ComponentType$Serializer : kotlinx/serialization/KSerializer { public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ComponentType; public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; @@ -1668,10 +1672,13 @@ public final class dev/kord/common/entity/DiscordClientStatus$Companion { public final class dev/kord/common/entity/DiscordComponent { public static final field Companion Ldev/kord/common/entity/DiscordComponent$Companion; - public synthetic fun (ILdev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;)V - public synthetic fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;)V + public synthetic fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/ComponentType; + public final fun component10 ()Ldev/kord/common/entity/optional/Optional; + public final fun component11 ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun component12 ()Ldev/kord/common/entity/optional/OptionalInt; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; @@ -1679,14 +1686,19 @@ public final class dev/kord/common/entity/DiscordComponent { public final fun component6 ()Ldev/kord/common/entity/optional/Optional; public final fun component7 ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun component8 ()Ldev/kord/common/entity/optional/Optional; - public final fun copy (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/common/entity/DiscordComponent; - public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordComponent;Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordComponent; + public final fun component9 ()Ldev/kord/common/entity/optional/Optional; + public final fun copy (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;)Ldev/kord/common/entity/DiscordComponent; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordComponent;Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordComponent; public fun equals (Ljava/lang/Object;)Z public final fun getComponents ()Ldev/kord/common/entity/optional/Optional; public final fun getCustomId ()Ldev/kord/common/entity/optional/Optional; public final fun getDisabled ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun getEmoji ()Ldev/kord/common/entity/optional/Optional; public final fun getLabel ()Ldev/kord/common/entity/optional/Optional; + public final fun getMaxValues ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun getMinValues ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun getOptions ()Ldev/kord/common/entity/optional/Optional; + public final fun getPlaceholder ()Ldev/kord/common/entity/optional/Optional; public final fun getStyle ()Ldev/kord/common/entity/optional/Optional; public final fun getType ()Ldev/kord/common/entity/ComponentType; public final fun getUrl ()Ldev/kord/common/entity/optional/Optional; @@ -3636,6 +3648,34 @@ public final class dev/kord/common/entity/DiscordRoleTags$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class dev/kord/common/entity/DiscordSelectOption { + public static final field Companion Ldev/kord/common/entity/DiscordSelectOption$Companion; + public synthetic fun (ILjava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;)V + public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getDefault ()Ldev/kord/common/entity/optional/OptionalBoolean; + public final fun getDescription ()Ldev/kord/common/entity/optional/Optional; + public final fun getEmoji ()Ldev/kord/common/entity/optional/Optional; + public final fun getLabel ()Ljava/lang/String; + public final fun getValue ()Ljava/lang/String; +} + +public final class dev/kord/common/entity/DiscordSelectOption$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/kord/common/entity/DiscordSelectOption$$serializer; + public static final synthetic field descriptor Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordSelectOption; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordSelectOption;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordSelectOption$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/DiscordShard { public static final field Companion Ldev/kord/common/entity/DiscordShard$Companion; public fun (II)V @@ -4474,17 +4514,18 @@ public final class dev/kord/common/entity/IntegrationExpireBehavior$Unknown : de public final class dev/kord/common/entity/InteractionCallbackData { public static final field Companion Ldev/kord/common/entity/InteractionCallbackData$Companion; public fun ()V - public synthetic fun (ILdev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V - public synthetic fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V + public synthetic fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/optional/OptionalSnowflake; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; public final fun component5 ()Ldev/kord/common/entity/optional/Optional; public final fun component6 ()Ldev/kord/common/entity/optional/Optional; - public final fun copy (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/common/entity/InteractionCallbackData; - public static synthetic fun copy$default (Ldev/kord/common/entity/InteractionCallbackData;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/common/entity/InteractionCallbackData; + public final fun component7 ()Ldev/kord/common/entity/optional/Optional; + public final fun copy (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/common/entity/InteractionCallbackData; + public static synthetic fun copy$default (Ldev/kord/common/entity/InteractionCallbackData;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/common/entity/InteractionCallbackData; public fun equals (Ljava/lang/Object;)Z public final fun getComponentType ()Ldev/kord/common/entity/optional/Optional; public final fun getCustomId ()Ldev/kord/common/entity/optional/Optional; @@ -4492,6 +4533,7 @@ public final class dev/kord/common/entity/InteractionCallbackData { public final fun getName ()Ldev/kord/common/entity/optional/Optional; public final fun getOptions ()Ldev/kord/common/entity/optional/Optional; public final fun getResolved ()Ldev/kord/common/entity/optional/Optional; + public final fun getValues ()Ldev/kord/common/entity/optional/Optional; public fun hashCode ()I public fun toString ()Ljava/lang/String; } diff --git a/common/src/main/kotlin/entity/DiscordComponent.kt b/common/src/main/kotlin/entity/DiscordComponent.kt index 85f452d274c..feb3cf2967b 100644 --- a/common/src/main/kotlin/entity/DiscordComponent.kt +++ b/common/src/main/kotlin/entity/DiscordComponent.kt @@ -3,6 +3,7 @@ package dev.kord.common.entity import dev.kord.common.annotation.KordPreview import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.common.entity.optional.OptionalInt import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,6 +12,7 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonNames /** * Represent a [intractable component within a message sent in Discord](https://discord.com/developers/docs/interactions/message-components#what-are-components). @@ -23,6 +25,10 @@ import kotlinx.serialization.encoding.Encoder * @property url a url for link-style buttons * @property disabled whether the button is disabled, default `false` * @property components a list of child components (for action rows) + * @property options the select menu options + * @property placeholder the placeholder text for the select menu + * @property minValues the minimum amount of [options] allowed + * @property maxValues the maximum amount of [options] allowed */ @KordPreview @Serializable @@ -35,7 +41,13 @@ data class DiscordComponent( val customId: Optional = Optional.Missing(), val url: Optional = Optional.Missing(), val disabled: OptionalBoolean = OptionalBoolean.Missing, - val components: Optional> = Optional.Missing() + val components: Optional> = Optional.Missing(), + val options: Optional> = Optional.Missing(), + val placeholder: Optional = Optional.Missing(), + @SerialName("min_values") + val minValues: OptionalInt = OptionalInt.Missing, + @SerialName("max_values") + val maxValues: OptionalInt = OptionalInt.Missing, ) /** @@ -62,6 +74,11 @@ sealed class ComponentType(val value: Int) { */ object Button : ComponentType(2) + /** + * A select menu for picking from choices. + */ + object SelectMenu : ComponentType(3) + companion object Serializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ComponentType", PrimitiveKind.INT) @@ -69,6 +86,7 @@ sealed class ComponentType(val value: Int) { when (val value = decoder.decodeInt()) { 1 -> ActionRow 2 -> Button + 3 -> SelectMenu else -> Unknown(value) } diff --git a/common/src/main/kotlin/entity/DiscordSelectOption.kt b/common/src/main/kotlin/entity/DiscordSelectOption.kt new file mode 100644 index 00000000000..62f94a70484 --- /dev/null +++ b/common/src/main/kotlin/entity/DiscordSelectOption.kt @@ -0,0 +1,23 @@ +package dev.kord.common.entity + +import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.OptionalBoolean +import kotlinx.serialization.Serializable + +/** + * Represent a [select option structure](https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure). + * + * @param label the user-facing name of the option, max 25 characters + * @param value the dev-define value of the option, max 100 characters + * @param description an additional description of the option, max 50 characters + * @param emoji the emoji to show in the option + * @param default whether to render this option as selected by default + */ +@Serializable +class DiscordSelectOption( + val label: String, + val value: String, + val description: Optional = Optional.Missing(), + val emoji: Optional = Optional.Missing(), + val default: OptionalBoolean = OptionalBoolean.Missing, +) diff --git a/common/src/main/kotlin/entity/Interactions.kt b/common/src/main/kotlin/entity/Interactions.kt index 740aa920fdf..3ef59142d86 100644 --- a/common/src/main/kotlin/entity/Interactions.kt +++ b/common/src/main/kotlin/entity/Interactions.kt @@ -257,7 +257,8 @@ data class InteractionCallbackData( @SerialName("custom_id") val customId: Optional = Optional.Missing(), @SerialName("component_type") - val componentType: Optional = Optional.Missing() + val componentType: Optional = Optional.Missing(), + val values: Optional> = Optional.Missing(), ) @Serializable(with = Option.Serializer::class) diff --git a/common/src/test/kotlin/json/InteractionTest.kt b/common/src/test/kotlin/json/InteractionTest.kt index 1fad5365c8b..bc5a8d63b97 100644 --- a/common/src/test/kotlin/json/InteractionTest.kt +++ b/common/src/test/kotlin/json/InteractionTest.kt @@ -2,6 +2,7 @@ package json import dev.kord.common.annotation.KordPreview import dev.kord.common.entity.* +import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.filterList import dev.kord.common.entity.optional.orEmpty import kotlinx.coroutines.coroutineScope @@ -117,4 +118,23 @@ class InteractionTest { } } } -} \ No newline at end of file + + @Test + fun `select menu can be deserialized`() { + val text = file("selectmenu") + + val interaction = json.decodeFromString(DiscordInteraction.serializer(), text) + with(interaction) { + applicationId shouldBe "845027738276462632" + channelId shouldBe "772908445358620702" + with(data){ + componentType shouldBe ComponentType.SelectMenu + customId shouldBe "class_select_1" + values shouldBe listOf("mage", "rogue") + } + guildId shouldBe "772904309264089089" + id shouldBe "847587388497854464" + } + } + +} diff --git a/common/src/test/kotlin/json/Util.kt b/common/src/test/kotlin/json/Util.kt index d02edbcfdc2..9d9ce38ab92 100644 --- a/common/src/test/kotlin/json/Util.kt +++ b/common/src/test/kotlin/json/Util.kt @@ -60,6 +60,10 @@ infix fun OptionalInt?.shouldBe(value: Int?){ Assertions.assertEquals(value, this.value) } +infix fun Optional.shouldBe(that: T?) { + Assertions.assertEquals(that, this.value) +} + infix fun T.shouldBe(that: T) { Assertions.assertEquals(that, this) } diff --git a/common/src/test/resources/json/interaction/selectmenu.json b/common/src/test/resources/json/interaction/selectmenu.json new file mode 100644 index 00000000000..cb5e41a10b1 --- /dev/null +++ b/common/src/test/resources/json/interaction/selectmenu.json @@ -0,0 +1,119 @@ +{ + "application_id": "845027738276462632", + "channel_id": "772908445358620702", + "data": { + "component_type":3, + "custom_id": "class_select_1", + "values": [ + "mage", + "rogue" + ] + }, + "guild_id": "772904309264089089", + "id": "847587388497854464", + "member": { + "avatar": null, + "deaf": false, + "is_pending": false, + "joined_at": "2020-11-02T19:25:47.248000+00:00", + "mute": false, + "nick": "Bot Man", + "pending": false, + "permissions": "17179869183", + "premium_since": null, + "roles": [ + "785609923542777878" + ], + "user":{ + "avatar": "a_d5efa99b3eeaa7dd43acca82f5692432", + "discriminator": "1337", + "id": "53908232506183680", + "public_flags": 131141, + "username": "Mason" + } + }, + "message":{ + "application_id": "845027738276462632", + "attachments": [], + "author": { + "avatar": null, + "bot": true, + "discriminator": "5284", + "id": "845027738276462632", + "public_flags": 0, + "username": "Interactions Test" + }, + "channel_id": "772908445358620702", + "components": [ + { + "components": [ + { + "custom_id": "class_select_1", + "max_values": 1, + "min_values": 1, + "options": [ + { + "description": "Sneak n stab", + "emoji":{ + "id": "625891304148303894", + "name": "rogue" + }, + "label": "Rogue", + "value": "rogue" + }, + { + "description": "Turn 'em into a sheep", + "emoji":{ + "id": "625891304081063986", + "name": "mage" + }, + "label": "Mage", + "value": "mage" + }, + { + "description": "You get heals when I'm done doing damage", + "emoji":{ + "id": "625891303795982337", + "name": "priest" + }, + "label": "Priest", + "value": "priest" + } + ], + "placeholder": "Choose a class", + "type": 3 + } + ], + "type": 1 + } + ], + "content": "Mason is looking for new arena partners. What classes do you play?", + "edited_timestamp": null, + "embeds": [], + "flags": 0, + "id": "847587334500646933", + "interaction": { + "id": "847587333942935632", + "name": "dropdown", + "type": 2, + "user": { + "avatar": "a_d5efa99b3eeaa7dd43acca82f5692432", + "discriminator": "1337", + "id": "53908232506183680", + "public_flags": 131141, + "username": "Mason" + } + }, + "mention_everyone": false, + "mention_roles":[], + "mentions":[], + "pinned": false, + "timestamp": "2021-05-27T21:29:27.956000+00:00", + "tts": false, + "type": 20, + "webhook_id": "845027738276462632" + }, + "token": "UNIQUE_TOKEN", + "type": 3, + "version": 1 +} diff --git a/core/api/core.api b/core/api/core.api index 318c865ee1b..f6c4968d527 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -1583,17 +1583,18 @@ public final class dev/kord/core/cache/data/ApplicationInfoData$Companion { public final class dev/kord/core/cache/data/ApplicationInteractionData { public static final field Companion Ldev/kord/core/cache/data/ApplicationInteractionData$Companion; public fun ()V - public synthetic fun (ILdev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V - public synthetic fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V + public synthetic fun (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/optional/OptionalSnowflake; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; public final fun component5 ()Ldev/kord/common/entity/optional/Optional; public final fun component6 ()Ldev/kord/common/entity/optional/Optional; - public final fun copy (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/ApplicationInteractionData; - public static synthetic fun copy$default (Ldev/kord/core/cache/data/ApplicationInteractionData;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/ApplicationInteractionData; + public final fun component7 ()Ldev/kord/common/entity/optional/Optional; + public final fun copy (Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/ApplicationInteractionData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/ApplicationInteractionData;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/ApplicationInteractionData; public fun equals (Ljava/lang/Object;)Z public final fun getComponentType ()Ldev/kord/common/entity/optional/Optional; public final fun getCustomId ()Ldev/kord/common/entity/optional/Optional; @@ -1601,6 +1602,7 @@ public final class dev/kord/core/cache/data/ApplicationInteractionData { public final fun getName ()Ldev/kord/common/entity/optional/Optional; public final fun getOptions ()Ldev/kord/common/entity/optional/Optional; public final fun getResolvedObjectsData ()Ldev/kord/common/entity/optional/Optional; + public final fun getValues ()Ldev/kord/common/entity/optional/Optional; public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -1810,10 +1812,13 @@ public final class dev/kord/core/cache/data/ClientStatusData$Companion { public final class dev/kord/core/cache/data/ComponentData { public static final field Companion Ldev/kord/core/cache/data/ComponentData$Companion; - public synthetic fun (ILdev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;)V - public synthetic fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/Optional;)V + public synthetic fun (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/ComponentType; + public final fun component10 ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun component11 ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun component12 ()Ldev/kord/common/entity/optional/Optional; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; @@ -1821,14 +1826,19 @@ public final class dev/kord/core/cache/data/ComponentData { public final fun component6 ()Ldev/kord/common/entity/optional/Optional; public final fun component7 ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun component8 ()Ldev/kord/common/entity/optional/Optional; - public final fun copy (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/ComponentData; - public static synthetic fun copy$default (Ldev/kord/core/cache/data/ComponentData;Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/ComponentData; + public final fun component9 ()Ldev/kord/common/entity/optional/Optional; + public final fun copy (Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/ComponentData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/ComponentData;Ldev/kord/common/entity/ComponentType;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/ComponentData; public fun equals (Ljava/lang/Object;)Z public final fun getComponents ()Ldev/kord/common/entity/optional/Optional; public final fun getCustomId ()Ldev/kord/common/entity/optional/Optional; public final fun getDisabled ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun getEmoji ()Ldev/kord/common/entity/optional/Optional; public final fun getLabel ()Ldev/kord/common/entity/optional/Optional; + public final fun getMaxValues ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun getMinValues ()Ldev/kord/common/entity/optional/OptionalInt; + public final fun getOptions ()Ldev/kord/common/entity/optional/Optional; + public final fun getPlaceholder ()Ldev/kord/common/entity/optional/Optional; public final fun getStyle ()Ldev/kord/common/entity/optional/Optional; public final fun getType ()Ldev/kord/common/entity/ComponentType; public final fun getUrl ()Ldev/kord/common/entity/optional/Optional; @@ -3399,6 +3409,45 @@ public final class dev/kord/core/cache/data/RoleTagsData$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public final class dev/kord/core/cache/data/SelectOptionData { + public static final field Companion Ldev/kord/core/cache/data/SelectOptionData$Companion; + public synthetic fun (ILjava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;)V + public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ldev/kord/common/entity/optional/Optional; + public final fun component4 ()Ldev/kord/common/entity/optional/Optional; + public final fun component5 ()Ldev/kord/common/entity/optional/OptionalBoolean; + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;)Ldev/kord/core/cache/data/SelectOptionData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/SelectOptionData;Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;ILjava/lang/Object;)Ldev/kord/core/cache/data/SelectOptionData; + public fun equals (Ljava/lang/Object;)Z + public final fun getDefault ()Ldev/kord/common/entity/optional/OptionalBoolean; + public final fun getDescription ()Ldev/kord/common/entity/optional/Optional; + public final fun getEmoji ()Ldev/kord/common/entity/optional/Optional; + public final fun getLabel ()Ljava/lang/String; + public final fun getValue ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class dev/kord/core/cache/data/SelectOptionData$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/kord/core/cache/data/SelectOptionData$$serializer; + public static final synthetic field descriptor Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/core/cache/data/SelectOptionData; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/core/cache/data/SelectOptionData;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/core/cache/data/SelectOptionData$Companion { + public final fun from (Ldev/kord/common/entity/DiscordSelectOption;)Ldev/kord/core/cache/data/SelectOptionData; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/core/cache/data/StageInstanceData { public static final field Companion Ldev/kord/core/cache/data/StageInstanceData$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V @@ -5541,7 +5590,9 @@ public final class dev/kord/core/entity/channel/WelcomeScreenChannel : dev/kord/ public final class dev/kord/core/entity/component/ActionRowComponent : dev/kord/core/entity/component/Component { public fun (Ldev/kord/core/cache/data/ComponentData;)V public final fun getButtons ()Ljava/util/List; + public final fun getComponents ()Ljava/util/List; public fun getData ()Ldev/kord/core/cache/data/ComponentData; + public final fun getSelectMenus ()Ljava/util/List; public fun getType ()Ldev/kord/common/entity/ComponentType; public fun toString ()Ljava/lang/String; } @@ -5572,6 +5623,33 @@ public final class dev/kord/core/entity/component/ComponentKt { public static final fun Component (Ldev/kord/core/cache/data/ComponentData;)Ldev/kord/core/entity/component/Component; } +public final class dev/kord/core/entity/component/SelectMenuComponent : dev/kord/core/entity/component/Component { + public fun (Ldev/kord/core/cache/data/ComponentData;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getCustomId ()Ljava/lang/String; + public fun getData ()Ldev/kord/core/cache/data/ComponentData; + public final fun getMaxValues ()I + public final fun getMinValues ()I + public final fun getOptions ()Ljava/util/List; + public final fun getPlaceholder ()Ljava/lang/String; + public fun getType ()Ldev/kord/common/entity/ComponentType; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class dev/kord/core/entity/component/SelectOption { + public fun (Ldev/kord/core/cache/data/SelectOptionData;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getData ()Ldev/kord/core/cache/data/SelectOptionData; + public final fun getDefault ()Ljava/lang/Boolean; + public final fun getDescription ()Ljava/lang/String; + public final fun getEmoji ()Ldev/kord/common/entity/DiscordPartialEmoji; + public final fun getLabel ()Ljava/lang/String; + public final fun getValue ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class dev/kord/core/entity/component/UnknownComponent : dev/kord/core/entity/component/Component { public fun (Ldev/kord/core/cache/data/ComponentData;)V public fun getData ()Ldev/kord/core/cache/data/ComponentData; @@ -5629,30 +5707,45 @@ public final class dev/kord/core/entity/interaction/ApplicationCommandSubCommand public final fun isDefault ()Z } -public abstract class dev/kord/core/entity/interaction/CommandInteraction : dev/kord/core/entity/interaction/Interaction { - public final fun getCommand ()Ldev/kord/core/entity/interaction/InteractionCommand; -} - -public final class dev/kord/core/entity/interaction/ComponentInteraction : dev/kord/core/entity/interaction/Interaction, dev/kord/core/behavior/interaction/ComponentInteractionBehavior { +public final class dev/kord/core/entity/interaction/ButtonInteraction : dev/kord/core/entity/interaction/ComponentInteraction { public fun (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V - public fun acknowledgeEphemeralDeferredMessageUpdate (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public fun acknowledgePublicDeferredMessageUpdate (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getApplicationId ()Ldev/kord/common/entity/Snowflake; - public final fun getComponent ()Ldev/kord/core/entity/component/ButtonComponent; - public final fun getComponentId ()Ljava/lang/String; + public fun getComponent ()Ldev/kord/core/entity/component/ButtonComponent; + public synthetic fun getComponent ()Ldev/kord/core/entity/component/Component; public fun getData ()Ldev/kord/core/cache/data/InteractionData; public fun getKord ()Ldev/kord/core/Kord; - public final fun getMessage ()Ldev/kord/core/entity/Message; public fun getSupplier ()Ldev/kord/core/supplier/EntitySupplier; - public fun getUser ()Ldev/kord/core/behavior/UserBehavior; public fun toString ()Ljava/lang/String; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/interaction/ComponentInteractionBehavior; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/interaction/InteractionBehavior; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; - public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/ComponentInteraction; + public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/ButtonInteraction; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/ComponentInteraction; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/Interaction; } +public abstract class dev/kord/core/entity/interaction/CommandInteraction : dev/kord/core/entity/interaction/Interaction { + public final fun getCommand ()Ldev/kord/core/entity/interaction/InteractionCommand; +} + +public abstract class dev/kord/core/entity/interaction/ComponentInteraction : dev/kord/core/entity/interaction/Interaction, dev/kord/core/behavior/interaction/ComponentInteractionBehavior { + public fun acknowledgeEphemeralDeferredMessageUpdate (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun acknowledgePublicDeferredMessageUpdate (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun equals (Ljava/lang/Object;)Z + public abstract fun getComponent ()Ldev/kord/core/entity/component/Component; + public final fun getComponentId ()Ljava/lang/String; + public final fun getMessage ()Ldev/kord/core/entity/Message; + public fun getUser ()Ldev/kord/core/behavior/UserBehavior; + public fun hashCode ()I + public abstract fun toString ()Ljava/lang/String; + public abstract fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/ComponentInteraction; +} + +public final class dev/kord/core/entity/interaction/ComponentInteractionKt { + public static final fun ComponentInteraction (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)Ldev/kord/core/entity/interaction/ComponentInteraction; + public static synthetic fun ComponentInteraction$default (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILjava/lang/Object;)Ldev/kord/core/entity/interaction/ComponentInteraction; +} + public final class dev/kord/core/entity/interaction/DmInteraction : dev/kord/core/entity/interaction/CommandInteraction { public fun (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V public synthetic fun (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -5890,6 +5983,24 @@ public final class dev/kord/core/entity/interaction/RootCommand : dev/kord/core/ public fun getRootName ()Ljava/lang/String; } +public final class dev/kord/core/entity/interaction/SelectMenuInteraction : dev/kord/core/entity/interaction/ComponentInteraction { + public fun (Ldev/kord/core/cache/data/InteractionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V + public fun getApplicationId ()Ldev/kord/common/entity/Snowflake; + public synthetic fun getComponent ()Ldev/kord/core/entity/component/Component; + public fun getComponent ()Ldev/kord/core/entity/component/SelectMenuComponent; + public fun getData ()Ldev/kord/core/cache/data/InteractionData; + public fun getKord ()Ldev/kord/core/Kord; + public fun getSupplier ()Ldev/kord/core/supplier/EntitySupplier; + public final fun getValues ()Ljava/util/List; + public fun toString ()Ljava/lang/String; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/interaction/ComponentInteractionBehavior; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/interaction/InteractionBehavior; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/ComponentInteraction; + public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/Interaction; + public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/interaction/SelectMenuInteraction; +} + public final class dev/kord/core/entity/interaction/SubCommand : dev/kord/core/entity/interaction/InteractionCommand { public fun (Ldev/kord/core/cache/data/ApplicationInteractionData;Ldev/kord/core/Kord;)V public final fun getData ()Ldev/kord/core/cache/data/ApplicationInteractionData; @@ -7626,7 +7737,9 @@ public abstract interface class dev/kord/core/supplier/EntitySupplyStrategy { public final class dev/kord/core/supplier/EntitySupplyStrategy$Companion { public final fun getCache ()Ldev/kord/core/supplier/EntitySupplyStrategy; + public final fun getCacheWithCachingRestFallback ()Ldev/kord/core/supplier/EntitySupplyStrategy; public final fun getCacheWithRestFallback ()Ldev/kord/core/supplier/EntitySupplyStrategy; + public final fun getCachingRest ()Ldev/kord/core/supplier/EntitySupplyStrategy; public final fun getRest ()Ldev/kord/core/supplier/EntitySupplyStrategy; public final fun invoke (Lkotlin/jvm/functions/Function1;)Ldev/kord/core/supplier/EntitySupplyStrategy; } @@ -7697,3 +7810,53 @@ public final class dev/kord/core/supplier/RestEntitySupplier : dev/kord/core/sup public fun toString ()Ljava/lang/String; } +public final class dev/kord/core/supplier/StoreEntitySupplier : dev/kord/core/supplier/EntitySupplier { + public fun (Ldev/kord/core/supplier/EntitySupplier;Ldev/kord/cache/api/DataCache;Ldev/kord/core/Kord;)V + public fun getChannel (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getChannelOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getChannelPins (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getChannelWebhooks (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getCurrentUserGuilds (I)Lkotlinx/coroutines/flow/Flow; + public fun getEmoji (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getEmojiOrNull (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getEmojis (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuild (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildBan (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildBanOrNull (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildBans (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuildChannels (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuildMembers (Ldev/kord/common/entity/Snowflake;I)Lkotlinx/coroutines/flow/Flow; + public fun getGuildOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildPreview (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildPreviewOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildRoles (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuildVoiceRegions (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuildWebhooks (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getGuildWidget (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuildWidgetOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getGuilds ()Lkotlinx/coroutines/flow/Flow; + public fun getMember (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getMemberOrNull (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getMessage (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getMessageOrNull (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getMessagesAfter (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;I)Lkotlinx/coroutines/flow/Flow; + public fun getMessagesAround (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;I)Lkotlinx/coroutines/flow/Flow; + public fun getMessagesBefore (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;I)Lkotlinx/coroutines/flow/Flow; + public fun getRegions ()Lkotlinx/coroutines/flow/Flow; + public fun getRole (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getRoleOrNull (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getSelf (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getSelfOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getStageInstance (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getStageInstanceOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getTemplate (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getTemplateOrNull (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getTemplates (Ldev/kord/common/entity/Snowflake;)Lkotlinx/coroutines/flow/Flow; + public fun getUser (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getUserOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getWebhook (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getWebhookOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getWebhookWithToken (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun getWebhookWithTokenOrNull (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + diff --git a/core/src/main/kotlin/cache/data/ComponentData.kt b/core/src/main/kotlin/cache/data/ComponentData.kt index db68257d90e..ca4376bcf5a 100644 --- a/core/src/main/kotlin/cache/data/ComponentData.kt +++ b/core/src/main/kotlin/cache/data/ComponentData.kt @@ -1,11 +1,9 @@ package dev.kord.core.cache.data -import dev.kord.common.entity.ButtonStyle -import dev.kord.common.entity.ComponentType -import dev.kord.common.entity.DiscordComponent -import dev.kord.common.entity.DiscordPartialEmoji +import dev.kord.common.entity.* import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.mapList import kotlinx.serialization.Serializable @@ -19,7 +17,11 @@ data class ComponentData( val customId: Optional = Optional.Missing(), val url: Optional = Optional.Missing(), val disabled: OptionalBoolean = OptionalBoolean.Missing, - val components: Optional> = Optional.Missing() + val components: Optional> = Optional.Missing(), + val placeholder: Optional = Optional.Missing(), + val minValues: OptionalInt = OptionalInt.Missing, + val maxValues: OptionalInt = OptionalInt.Missing, + val options: Optional> = Optional.Missing() ) { companion object { @@ -33,7 +35,10 @@ data class ComponentData( customId, url, disabled, - components.mapList { from(it) } + components.mapList { from(it) }, + placeholder = placeholder, + minValues = minValues, + maxValues = maxValues ) } diff --git a/core/src/main/kotlin/cache/data/InteractionData.kt b/core/src/main/kotlin/cache/data/InteractionData.kt index 4884442ee9d..5033b51ece4 100644 --- a/core/src/main/kotlin/cache/data/InteractionData.kt +++ b/core/src/main/kotlin/cache/data/InteractionData.kt @@ -94,7 +94,8 @@ data class ApplicationInteractionData( val options: Optional> = Optional.Missing(), val resolvedObjectsData: Optional = Optional.Missing(), val customId: Optional = Optional.Missing(), - val componentType: Optional = Optional.Missing() + val componentType: Optional = Optional.Missing(), + val values: Optional> = Optional.Missing() ) { companion object { @@ -109,7 +110,8 @@ data class ApplicationInteractionData( options.map { it.map { OptionData.from(it) } }, resolved.map { ResolvedObjectsData.from(it, guildId) }, customId, - componentType + componentType, + values = values, ) } } @@ -150,5 +152,3 @@ object NotSerializable : KSerializer { override val descriptor: SerialDescriptor = String.serializer().descriptor override fun serialize(encoder: Encoder, value: Any?) = error("This operation is not supported.") } - - diff --git a/core/src/main/kotlin/cache/data/SelectOptionData.kt b/core/src/main/kotlin/cache/data/SelectOptionData.kt new file mode 100644 index 00000000000..169c0c2f050 --- /dev/null +++ b/core/src/main/kotlin/cache/data/SelectOptionData.kt @@ -0,0 +1,32 @@ +package dev.kord.core.cache.data + +import dev.kord.common.entity.DiscordPartialEmoji +import dev.kord.common.entity.DiscordSelectOption +import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.OptionalBoolean +import kotlinx.serialization.Serializable + +@Serializable +data class SelectOptionData( + val label: String, + val value: String, + val description: Optional = Optional.Missing(), + val emoji: Optional = Optional.Missing(), + val default: OptionalBoolean = OptionalBoolean.Missing +) { + + companion object { + + fun from(entity: DiscordSelectOption): SelectOptionData = with(entity){ + SelectOptionData( + label = label, + value = value, + description = description, + emoji = emoji, + default = default + ) + } + + } + +} diff --git a/core/src/main/kotlin/entity/component/ActionRowComponent.kt b/core/src/main/kotlin/entity/component/ActionRowComponent.kt index 98a10f5f1d0..7ef68e1594a 100644 --- a/core/src/main/kotlin/entity/component/ActionRowComponent.kt +++ b/core/src/main/kotlin/entity/component/ActionRowComponent.kt @@ -14,14 +14,25 @@ class ActionRowComponent(override val data: ComponentData) : Component { override val type: ComponentType get() = ComponentType.ActionRow + /** + * All components nested inside this component. + */ + val components: List + get() = data.components.orEmpty().map { Component(it) } /** - * The buttons that are nested inside this component + * The buttons that are nested inside this component. + * @see components */ val buttons: List - get() = data.components.orEmpty() - .filter { it.type == ComponentType.Button } - .map { ButtonComponent(it) } + get() = components.filterIsInstance() + + /** + * The buttons that are nested inside this component. + * @see components + */ + val selectMenus: List + get() = components.filterIsInstance() override fun toString(): String = "ActionRowComponent(data=$data)" diff --git a/core/src/main/kotlin/entity/component/ButtonComponent.kt b/core/src/main/kotlin/entity/component/ButtonComponent.kt index 52b66516bc4..cd9b43dc21f 100644 --- a/core/src/main/kotlin/entity/component/ButtonComponent.kt +++ b/core/src/main/kotlin/entity/component/ButtonComponent.kt @@ -8,6 +8,7 @@ import dev.kord.core.cache.data.ComponentData import dev.kord.core.entity.ReactionEmoji import dev.kord.core.entity.interaction.ComponentInteraction import dev.kord.core.event.interaction.InteractionCreateEvent +import dev.kord.core.entity.interaction.ButtonInteraction /** * An interactive component rendered on a Message. @@ -47,7 +48,7 @@ class ButtonComponent(override val data: ComponentData) : Component { } /** - * The custom identifier for any [ComponentInteractions][ComponentInteraction] + * The custom identifier for any [ComponentInteractions][ButtonInteraction] * this button will trigger. Present if this button is not a link button. */ val customId: String? get() = data.customId.value diff --git a/core/src/main/kotlin/entity/component/Component.kt b/core/src/main/kotlin/entity/component/Component.kt index e32f80ea8d3..fc9c68b84b6 100644 --- a/core/src/main/kotlin/entity/component/Component.kt +++ b/core/src/main/kotlin/entity/component/Component.kt @@ -15,6 +15,7 @@ sealed interface Component { * The type of component. * @see ButtonComponent * @see ActionRowComponent + * @see SelectMenuComponent * @see UnknownComponent */ val type: ComponentType get() = data.type @@ -26,11 +27,13 @@ sealed interface Component { * Creates a [Component] from the [data]. * @see ActionRowComponent * @see ButtonComponent + * @see SelectMenuComponent * @see UnknownComponent */ @KordPreview fun Component(data: ComponentData): Component = when (data.type) { ComponentType.ActionRow -> ActionRowComponent(data) ComponentType.Button -> ButtonComponent(data) + ComponentType.SelectMenu -> SelectMenuComponent(data) is ComponentType.Unknown -> UnknownComponent(data) } diff --git a/core/src/main/kotlin/entity/component/SelectMenuComponent.kt b/core/src/main/kotlin/entity/component/SelectMenuComponent.kt new file mode 100644 index 00000000000..f60c8f18440 --- /dev/null +++ b/core/src/main/kotlin/entity/component/SelectMenuComponent.kt @@ -0,0 +1,99 @@ +package dev.kord.core.entity.component + +import dev.kord.common.annotation.KordPreview +import dev.kord.common.entity.DiscordPartialEmoji +import dev.kord.common.entity.optional.orEmpty +import dev.kord.common.entity.optional.value +import dev.kord.core.cache.data.ComponentData +import dev.kord.core.cache.data.SelectOptionData +import dev.kord.core.entity.Message +import dev.kord.core.entity.interaction.SelectMenuInteraction + +/** + * An interactive dropdown menu rendered on a [Message] that consists of multiple [options]. + */ +@KordPreview +class SelectMenuComponent(override val data: ComponentData) : Component { + + /** + * The custom identifier for any [ComponentInteractions][SelectMenuInteraction] + * this select menu will trigger. + */ + val customId: String get() = data.customId.value!! + + /** + * The placeholder value if no value has been selected, null if not set. + */ + val placeholder: String? get() = data.placeholder.value + + /** + * The possible options to choose from. + */ + val options: List get() = data.options.orEmpty().map { SelectOption(it) } + + /** + * The minimum amount of [options] that can be chosen, default `1`. + */ + val minValues: Int get() = data.minValues.orElse(1) + + /** + * The maximum amount of [options] that can be chosen, default `1`. + */ + val maxValues: Int get() = data.maxValues.orElse(1) + + override fun equals(other: Any?): Boolean { + if (other !is SelectMenuComponent) return false + + return other.data == data + } + + override fun hashCode(): Int { + return data.hashCode() + } + + override fun toString(): String = "SelectMenuComponent(data=$data)" +} + +/** + * An option in a [SelectMenuComponent]. + */ +class SelectOption(val data: SelectOptionData) { + + /** + * The user-facing name of the option, max 25 characters. + */ + val label: String get() = data.label + + /** + * The dev-define value of the option, max 100 characters. + */ + val value: String get() = data.value + + /** + * An additional description of the option, max 50 characters. Null if not set. + */ + val description: String? get() = data.description.value + + /** + * The emoji to show in the option. Null if not set. + */ + val emoji: DiscordPartialEmoji? = data.emoji.value + + /** + * Whether this option is selected by default. + */ + val default: Boolean? = data.default.value + + override fun equals(other: Any?): Boolean { + if (other !is SelectOption) return false + + return other.data == data + } + + override fun hashCode(): Int { + return data.hashCode() + } + + override fun toString(): String = "SelectOption(data=$data)" + +} diff --git a/core/src/main/kotlin/entity/interaction/ComponentInteraction.kt b/core/src/main/kotlin/entity/interaction/ComponentInteraction.kt new file mode 100644 index 00000000000..b90cc839fbd --- /dev/null +++ b/core/src/main/kotlin/entity/interaction/ComponentInteraction.kt @@ -0,0 +1,137 @@ +package dev.kord.core.entity.interaction + +import dev.kord.common.annotation.KordPreview +import dev.kord.common.entity.ComponentType +import dev.kord.common.entity.Snowflake +import dev.kord.common.entity.optional.orEmpty +import dev.kord.common.entity.optional.unwrap +import dev.kord.core.Kord +import dev.kord.core.behavior.UserBehavior +import dev.kord.core.behavior.interaction.ComponentInteractionBehavior +import dev.kord.core.cache.data.InteractionData +import dev.kord.core.entity.Message +import dev.kord.core.entity.component.ActionRowComponent +import dev.kord.core.entity.component.ButtonComponent +import dev.kord.core.entity.component.Component +import dev.kord.core.entity.component.SelectMenuComponent +import dev.kord.core.supplier.EntitySupplier +import dev.kord.core.supplier.EntitySupplyStrategy +import dev.kord.rest.builder.component.SelectMenuBuilder + +/** + * An interaction created from a user interaction with a [Component]. + * + * @see ButtonInteraction + * @see SelectMenuInteraction + */ +@KordPreview +sealed class ComponentInteraction : Interaction(), ComponentInteractionBehavior { + + override val user: UserBehavior + get() = UserBehavior(data.member.value!!.userId, kord) + + /** + * The message that contains the interacted component, null if the message is ephemeral. + */ + val message: Message? + get() = data.message.unwrap { Message(it, kord, supplier) } + + /** + * The [ButtonComponent.customId] or [SelectMenuComponent.customId] that triggered the interaction. + */ + val componentId: String get() = data.data.customId.value!! + + /** + * The [Component] the user interacted with, null if the message is ephemeral. + */ + abstract val component: Component? + + abstract override fun withStrategy(strategy: EntitySupplyStrategy<*>): ComponentInteraction + + abstract override fun toString(): String + + override fun equals(other: Any?): Boolean { + if (other !is Interaction) return false + + return other.data == data + } + + override fun hashCode(): Int = data.hashCode() +} + +/** + * Creates a [ComponentInteraction] with the given [data], [applicationId], [kord] and [supplier]. + * + * @throws IllegalArgumentException if the interaction is not from a [ButtonComponent] or a [SelectMenuComponent]. + */ +@KordPreview +fun ComponentInteraction( + data: InteractionData, + applicationId: Snowflake, + kord: Kord, + supplier: EntitySupplier = kord.defaultSupplier, +): ComponentInteraction = when (val type = data.data.componentType.value) { + ComponentType.Button -> ButtonInteraction(data, applicationId, kord, supplier) + ComponentType.SelectMenu -> SelectMenuInteraction(data, applicationId, kord, supplier) + else -> throw IllegalArgumentException("unknown component type for interaction: $type") +} + +/** + * An interaction created from a user pressing a [ButtonComponent]. + */ +@KordPreview +class ButtonInteraction( + override val data: InteractionData, + override val applicationId: Snowflake, + override val kord: Kord, + override val supplier: EntitySupplier +) : ComponentInteraction() { + + override val component: ButtonComponent? + get() = message?.components.orEmpty() + .filterIsInstance() + .flatMap { it.buttons } + .firstOrNull { it.customId == componentId } + + override fun withStrategy(strategy: EntitySupplyStrategy<*>): ButtonInteraction { + return ButtonInteraction(data, applicationId, kord, strategy.supply(kord)) + } + + override fun toString(): String = + "ButtonInteraction(data=$data, applicationId=$applicationId, kord=$kord, supplier=$supplier, user=$user)" + +} + +/** + * An interaction created from a user interacting with a [SelectMenuComponent]. + */ +@KordPreview +class SelectMenuInteraction( + override val data: InteractionData, + override val applicationId: Snowflake, + override val kord: Kord, + override val supplier: EntitySupplier +) : ComponentInteraction() { + + /** + * The selected values, the expected range should between 0 and 25. + * + * @see [SelectMenuBuilder.minimumValues] + * @see [SelectMenuBuilder.maximumValues] + */ + val values: List get() = data.data.values.orEmpty() + + override val component: SelectMenuComponent? + get() = message?.components.orEmpty() + .filterIsInstance() + .flatMap { it.selectMenus } + .firstOrNull { it.customId == componentId } + + override fun withStrategy(strategy: EntitySupplyStrategy<*>): SelectMenuInteraction { + return SelectMenuInteraction(data, applicationId, kord, strategy.supply(kord)) + } + + override fun toString(): String = + "SelectMenuInteraction(data=$data, applicationId=$applicationId, kord=$kord, supplier=$supplier, user=$user)" + +} diff --git a/core/src/main/kotlin/entity/interaction/Interaction.kt b/core/src/main/kotlin/entity/interaction/Interaction.kt index 096d1784ddb..6e4b7eeb8b6 100644 --- a/core/src/main/kotlin/entity/interaction/Interaction.kt +++ b/core/src/main/kotlin/entity/interaction/Interaction.kt @@ -350,54 +350,6 @@ class DmInteraction( DmInteraction(data, applicationId, kord, strategy.supply(kord)) } -/** - * An [Interaction] that was made with a [Component]. - */ -@KordPreview -class ComponentInteraction( - override val data: InteractionData, - override val applicationId: Snowflake, - override val kord: Kord, - override val supplier: EntitySupplier -) : Interaction(), ComponentInteractionBehavior { - - override val user: UserBehavior = UserBehavior(data.member.value!!.userId, kord) - - /** - * The message that contains the interacted component, null if the message is ephemeral. - */ - val message: Message? - get() = data.message.unwrap { - Message(it, kord, supplier) - } - - /** - * The [ButtonComponent.customId] that triggered the interaction. - */ - val componentId: String get() = data.data.customId.value!! - - /** - * The [ButtonComponent] the user interacted with, null if the message is ephemeral. - * - * @see Component - */ - val component: ButtonComponent? - get() = message?.components.orEmpty() - .filterIsInstance() - .flatMap { it.buttons } - .firstOrNull { it.customId == componentId } - - - override fun withStrategy(strategy: EntitySupplyStrategy<*>): ComponentInteraction = ComponentInteraction( - data, applicationId, kord, strategy.supply(kord) - ) - - override fun toString(): String { - return "ComponentInteraction(data=$data, applicationId=$applicationId, kord=$kord, supplier=$supplier, user=$user)" - } - -} - @KordPreview class GuildInteraction( override val data: InteractionData, diff --git a/core/src/main/kotlin/gateway/MasterGateway.kt b/core/src/main/kotlin/gateway/MasterGateway.kt index 09c7fa93e11..fc1d68a879f 100644 --- a/core/src/main/kotlin/gateway/MasterGateway.kt +++ b/core/src/main/kotlin/gateway/MasterGateway.kt @@ -25,7 +25,7 @@ class MasterGateway( */ val averagePing get(): Duration? { - val pings = gateways.values.mapNotNull { it.ping.value?.inWholeMilliseconds } + val pings = gateways.values.mapNotNull { it.ping.value?.inWholeMicroseconds } if (pings.isEmpty()) return null return Duration.microseconds(pings.average()) diff --git a/core/src/main/kotlin/supplier/CacheAwareRestSupplier.kt b/core/src/main/kotlin/supplier/CacheAwareRestSupplier.kt new file mode 100644 index 00000000000..fcdf0442a79 --- /dev/null +++ b/core/src/main/kotlin/supplier/CacheAwareRestSupplier.kt @@ -0,0 +1,163 @@ +package dev.kord.core.supplier + +import dev.kord.cache.api.DataCache +import dev.kord.cache.api.put +import dev.kord.common.entity.Snowflake +import dev.kord.core.Kord +import dev.kord.core.entity.* +import dev.kord.core.entity.channel.Channel +import dev.kord.core.entity.channel.GuildChannel +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.onEach + +/** + * [EntitySupplier] that delegates to another [EntitySupplier] to resolve entities. + * + * Resolved entities will always be stored in [cache] if it wasn't null or empty for flows. + */ +class StoreEntitySupplier( + private val supplier: EntitySupplier, + private val cache: DataCache, + private val kord: Kord +) : EntitySupplier { + + + override val guilds: Flow + get() = storeOnEach(supplier.guilds) { it.data } + + override val regions: Flow + get() = storeOnEach(supplier.regions) { it.data } + + + override suspend fun getGuildOrNull(id: Snowflake): Guild? { + return storeAndReturn(supplier.getGuildOrNull(id)) { it.data } + } + + override suspend fun getGuildPreviewOrNull(guildId: Snowflake): GuildPreview? { + return storeAndReturn(supplier.getGuildPreviewOrNull(guildId)) { it.data } + } + + override suspend fun getGuildWidgetOrNull(guildId: Snowflake): GuildWidget? { + return storeAndReturn(supplier.getGuildWidgetOrNull(guildId)) { it.data } + } + + override suspend fun getChannelOrNull(id: Snowflake): Channel? { + return storeAndReturn(supplier.getChannelOrNull(id)) { it.data } + } + + override fun getGuildChannels(guildId: Snowflake): Flow { + return storeOnEach(supplier.getGuildChannels(guildId)) { it.data } + + } + + override fun getChannelPins(channelId: Snowflake): Flow { + return storeOnEach(supplier.getChannelPins(channelId)) { it.data } + + } + + override suspend fun getMemberOrNull(guildId: Snowflake, userId: Snowflake): Member? { + return storeAndReturn(supplier.getMemberOrNull(guildId, userId)) { it.data } + } + + override suspend fun getMessageOrNull(channelId: Snowflake, messageId: Snowflake): Message? { + return storeAndReturn(supplier.getMessageOrNull(channelId, messageId)) { it.data } + } + + override fun getMessagesAfter(messageId: Snowflake, channelId: Snowflake, limit: Int): Flow { + return storeOnEach(supplier.getMessagesAfter(messageId, channelId, limit)) { it.data } + } + + override fun getMessagesBefore(messageId: Snowflake, channelId: Snowflake, limit: Int): Flow { + return storeOnEach(supplier.getMessagesBefore(messageId, channelId, limit)) { it.data } + } + + override fun getMessagesAround(messageId: Snowflake, channelId: Snowflake, limit: Int): Flow { + return storeOnEach(supplier.getMessagesAround(messageId, channelId, limit)) { it.data } + } + + override suspend fun getSelfOrNull(): User? { + return storeAndReturn(supplier.getSelfOrNull()) { it.data } + } + + override suspend fun getUserOrNull(id: Snowflake): User? { + return storeAndReturn(supplier.getUserOrNull(id)) { it.data } + } + + override suspend fun getRoleOrNull(guildId: Snowflake, roleId: Snowflake): Role? { + return storeAndReturn(supplier.getRoleOrNull(guildId, roleId)) { it.data } + } + + override fun getGuildRoles(guildId: Snowflake): Flow { + return storeOnEach(supplier.getGuildRoles(guildId)) { it.data } + } + + override suspend fun getGuildBanOrNull(guildId: Snowflake, userId: Snowflake): Ban? { + return storeAndReturn(supplier.getGuildBanOrNull(guildId, userId)) { it.data } + } + + override fun getGuildBans(guildId: Snowflake): Flow { + return storeOnEach(supplier.getGuildBans(guildId)) { it.data } + } + + override fun getGuildMembers(guildId: Snowflake, limit: Int): Flow { + return storeOnEach(supplier.getGuildMembers(guildId, limit)) { it.data } + } + + override fun getGuildVoiceRegions(guildId: Snowflake): Flow { + return storeOnEach(supplier.getGuildVoiceRegions(guildId)) { it.data } + } + + override suspend fun getEmojiOrNull(guildId: Snowflake, emojiId: Snowflake): GuildEmoji? { + return storeAndReturn(supplier.getEmojiOrNull(guildId, emojiId)) { it.data } + } + + override fun getEmojis(guildId: Snowflake): Flow { + return storeOnEach(supplier.getEmojis(guildId)) { it.data } + + } + + override fun getCurrentUserGuilds(limit: Int): Flow { + return storeOnEach(supplier.getCurrentUserGuilds(limit)) { it.data } + + } + + override fun getChannelWebhooks(channelId: Snowflake): Flow { + return storeOnEach(supplier.getChannelWebhooks(channelId)) { it.data } + } + + override fun getGuildWebhooks(guildId: Snowflake): Flow { + return storeOnEach(supplier.getGuildWebhooks(guildId)) { it.data } + } + + override suspend fun getWebhookOrNull(id: Snowflake): Webhook? { + return storeAndReturn(supplier.getWebhookOrNull(id)) { it.data } + } + + override suspend fun getWebhookWithTokenOrNull(id: Snowflake, token: String): Webhook? { + return storeAndReturn(supplier.getWebhookWithTokenOrNull(id, token)) { it.data } + } + + override suspend fun getTemplateOrNull(code: String): Template? { + return storeAndReturn(supplier.getTemplateOrNull(code)) { it.data } + } + + override fun getTemplates(guildId: Snowflake): Flow