commonMain.entity.component.Component.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-core-jvm Show documentation
Show all versions of kord-core-jvm Show documentation
Idiomatic Kotlin Wrapper for The Discord API
The newest version!
package dev.kord.core.entity.component
import dev.kord.common.entity.ComponentType
import dev.kord.core.cache.data.ChatComponentData
import dev.kord.core.cache.data.ComponentData
import dev.kord.core.cache.data.TextInputComponentData
import dev.kord.core.entity.Message
/**
* An interactive element inside a [Message].
*/
public sealed interface Component {
/**
* The type of component.
* @see ButtonComponent
* @see ActionRowComponent
* @see SelectMenuComponent
* @see UnknownComponent
*/
public val type: ComponentType get() = data.type
public val data: ComponentData
}
/**
* Creates a [Component] from the [data].
* @see ActionRowComponent
* @see ButtonComponent
* @see SelectMenuComponent
* @see UnknownComponent
*/
public fun Component(data: ComponentData): Component = when (data.type) {
ComponentType.ActionRow -> ActionRowComponent(data)
ComponentType.Button -> ButtonComponent(data as ChatComponentData)
ComponentType.StringSelect -> StringSelectComponent(data)
ComponentType.UserSelect -> UserSelectComponent(data)
ComponentType.RoleSelect -> RoleSelectComponent(data)
ComponentType.MentionableSelect -> MentionableSelectComponent(data)
ComponentType.ChannelSelect -> ChannelSelectComponent(data)
ComponentType.TextInput -> TextInputComponent(data as TextInputComponentData)
is ComponentType.Unknown -> UnknownComponent(data)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy