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

commonMain.cache.data.UserData.kt Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
package dev.kord.core.cache.data

import dev.kord.cache.api.data.DataDescription
import dev.kord.cache.api.data.description
import dev.kord.common.entity.DiscordOptionallyMemberUser
import dev.kord.common.entity.DiscordUser
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.UserFlags
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import kotlinx.serialization.Serializable

private val WebhookData.nullableUserId get() = userId.value

@Serializable
public data class UserData(
    val id: Snowflake,
    val username: String,
    val discriminator: Optional = Optional.Missing(),
    val globalName: Optional = Optional.Missing(),
    val avatar: String? = null,
    val bot: OptionalBoolean = OptionalBoolean.Missing,
    val publicFlags: Optional = Optional.Missing(),
    val banner: String? = null,
    val accentColor: Int? = null,
    val avatarDecoration: Optional = Optional.Missing()
) {
    public companion object {

        public val description: DataDescription = description(UserData::id) {
            link(UserData::id to MemberData::userId)
            link(UserData::id to WebhookData::nullableUserId)
            link(UserData::id to VoiceStateData::userId)
            link(UserData::id to PresenceData::userId)
        }

        public fun from(entity: DiscordUser): UserData = with(entity) {
            UserData(id, username, discriminator, globalName, avatar, bot, publicFlags, banner, accentColor, avatarDecoration)
        }

        public fun from(entity: DiscordOptionallyMemberUser): UserData = with(entity) {
            UserData(id, username, discriminator, globalName, avatar, bot, publicFlags)
        }

    }
}

public fun DiscordUser.toData(): UserData = UserData.from(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy