commonMain.cache.data.InteractionData.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-core Show documentation
Show all versions of kord-core Show documentation
Idiomatic Kotlin Wrapper for The Discord API
package dev.kord.core.cache.data
import dev.kord.common.Locale
import dev.kord.common.annotation.KordExperimental
import dev.kord.common.entity.*
import dev.kord.common.entity.optional.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable
public data class InteractionData(
val id: Snowflake,
val applicationId: Snowflake,
val type: InteractionType,
val data: ApplicationInteractionData,
val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
val channel: Optional = Optional.Missing(),
val channelId: OptionalSnowflake = OptionalSnowflake.Missing,
val member: Optional = Optional.Missing(),
val user: Optional = Optional.Missing(),
val token: String,
val permissions: Optional = Optional.Missing(),
val version: Int,
val message: Optional = Optional.Missing(),
val appPermissions: Optional = Optional.Missing(),
val locale: Optional = Optional.Missing(),
val guildLocale: Optional = Optional.Missing()
) {
public companion object {
public fun from(interaction: DiscordInteraction): InteractionData {
return with(interaction) {
InteractionData(
id,
applicationId,
type,
ApplicationInteractionData.from(data, guildId.value),
guildId,
channel.map { ChannelData.from(it) },
channelId,
member.map { it.toData(it.user.value!!.id, guildId.value!!) },
//borrow user from member if present
user.switchOnMissing(member.flatMap { it.user }).map { it.toData() },
token,
member.map { it.permissions },
version,
message.map {
MessageData.from(it)
},
appPermissions,
locale,
guildLocale
)
}
}
}
}
@Serializable
public data class ResolvedObjectsData(
val members: Optional