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
import kotlin.DeprecationLevel.WARNING

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

@Serializable
public data class UserData(
    val id: Snowflake,
    val username: String,
    @Deprecated(
        "Discord's username system is changing and discriminators are being removed, see " +
            "https://discord.com/developers/docs/change-log#unique-usernames-on-discord for details.",
        level = WARNING,
    )
    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
) {
    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, @Suppress("DEPRECATION") discriminator, globalName, avatar, bot, publicFlags, banner, accentColor)
        }

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

    }
}

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy