All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.entity.component.ActionRowComponent.kt Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
package dev.kord.core.entity.component

import dev.kord.common.entity.ComponentType
import dev.kord.common.entity.optional.orEmpty
import dev.kord.core.cache.data.ComponentData

/**
 * A non-interactive container component for other types of component.
 */
public class ActionRowComponent(override val data: ComponentData) : Component {

    override val type: ComponentType.ActionRow
        get() = ComponentType.ActionRow

    /**
     * All [Component]s that are nested inside this action row.
     */
    public val components: List
        get() = data.components.orEmpty().map { Component(it) }

    /**
     * The [ButtonComponent]s of this action row that are not a link button, indexed by their
     * [customId][ButtonComponent.customId] (which is always present on these buttons).
     *
     * @see components
     */
    public val interactionButtons: Map
        get() = components.filterIsInstance()
            .filter { it.customId != null }
            .associateBy { it.customId!! }

    /**
     * The [ButtonComponent]s of this action row that are a link button. [url][ButtonComponent.url] is always present on
     * these buttons.
     *
     * @see components
     */
    public val linkButtons: List
        get() = components.filterIsInstance().filter { it.url != null }

    /**
     * The [SelectMenuComponent]s of this action row, indexed by their [customId][SelectMenuComponent.customId].
     *
     * @see components
     */
    public val selectMenus: Map
        get() = components.filterIsInstance().associateBy { it.customId }

    /**
     * The [TextInputComponent]s of this action row, indexed by their [customId][TextInputComponent.customId].
     *
     * @see components
     */
    public val textInputs: Map
        get() = components.filterIsInstance().associateBy { it.customId }

    override fun toString(): String = "ActionRowComponent(data=$data)"

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy