diff --git a/CHANGELOG.md b/CHANGELOG.md index 384ba1d430a7..9e895e423331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * `PublicFollowupMessageCreateBuilder` * `EphemeralFollowupMessageCreateBuilder` * `FollowupMessageModifyRequest` +* `ComponentInteraction` ## Changes @@ -23,6 +24,11 @@ when editing a message. This makes it possible to remove fields from a message without providing a substitution. * `FollowupMessageBuilder` no longer has the `tts` field, since it does not apply to all its subclasses. +## Fixes + +* `ActionRowComponent` properly returns its children. +* `ComponentInteraction#button` is now nullable as its documentation implies. + # 0.7.0 ## Additions diff --git a/core/src/main/kotlin/cache/data/ComponentData.kt b/core/src/main/kotlin/cache/data/ComponentData.kt index 8d53f3c391e4..db68257d90e6 100644 --- a/core/src/main/kotlin/cache/data/ComponentData.kt +++ b/core/src/main/kotlin/cache/data/ComponentData.kt @@ -6,6 +6,7 @@ import dev.kord.common.entity.DiscordComponent import dev.kord.common.entity.DiscordPartialEmoji import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.common.entity.optional.mapList import kotlinx.serialization.Serializable @Serializable @@ -23,7 +24,7 @@ data class ComponentData( companion object { - fun from(entity: DiscordComponent) = with(entity) { + fun from(entity: DiscordComponent): ComponentData = with(entity) { ComponentData( type, style, @@ -31,7 +32,8 @@ data class ComponentData( emoji, customId, url, - disabled + disabled, + components.mapList { from(it) } ) } diff --git a/core/src/main/kotlin/entity/interaction/Interaction.kt b/core/src/main/kotlin/entity/interaction/Interaction.kt index a399fa2acf30..bd1424603fcb 100644 --- a/core/src/main/kotlin/entity/interaction/Interaction.kt +++ b/core/src/main/kotlin/entity/interaction/Interaction.kt @@ -1,7 +1,10 @@ package dev.kord.core.entity.interaction import dev.kord.common.annotation.KordPreview -import dev.kord.common.entity.* +import dev.kord.common.entity.CommandArgument +import dev.kord.common.entity.InteractionType +import dev.kord.common.entity.Permissions +import dev.kord.common.entity.Snowflake import dev.kord.common.entity.optional.* import dev.kord.core.Kord import dev.kord.core.KordObject @@ -11,25 +14,18 @@ import dev.kord.core.behavior.MemberBehavior import dev.kord.core.behavior.UserBehavior import dev.kord.core.behavior.channel.GuildMessageChannelBehavior import dev.kord.core.behavior.interaction.ComponentInteractionBehavior -import dev.kord.core.behavior.interaction.EphemeralInteractionResponseBehavior import dev.kord.core.behavior.interaction.InteractionBehavior -import dev.kord.core.behavior.interaction.PublicInteractionResponseBehavior import dev.kord.core.cache.data.ApplicationInteractionData import dev.kord.core.cache.data.InteractionData import dev.kord.core.cache.data.ResolvedObjectsData import dev.kord.core.entity.* import dev.kord.core.entity.channel.DmChannel import dev.kord.core.entity.channel.ResolvedChannel +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.supplier.EntitySupplier import dev.kord.core.supplier.EntitySupplyStrategy -import dev.kord.rest.builder.interaction.UpdateMessageInteractionResponseCreateBuilder -import dev.kord.rest.json.request.InteractionApplicationCommandCallbackData -import dev.kord.rest.json.request.InteractionResponseCreateRequest -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract /** * An instance of [Interaction] (https://discord.com/developers/docs/interactions/slash-commands#interaction) @@ -385,9 +381,11 @@ class ComponentInteraction( * * @see Component */ - val component: ButtonComponent + val component: ButtonComponent? get() = message?.components.orEmpty() - .filterIsInstance().first { it.customId == componentId } + .filterIsInstance() + .flatMap { it.buttons } + .firstOrNull { it.customId == componentId } override fun withStrategy(strategy: EntitySupplyStrategy<*>): ComponentInteraction = ComponentInteraction(