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

commonMain.cache.data.RoleData.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.*
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.map
import kotlinx.serialization.Serializable

@Serializable
public data class RoleData(
    val id: Snowflake,
    val guildId: Snowflake,
    val name: String,
    val color: Int,
    val hoisted: Boolean,
    val icon: Optional = Optional.Missing(),
    val unicodeEmoji: Optional = Optional.Missing(),
    val position: Int,
    val permissions: Permissions,
    val managed: Boolean,
    val mentionable: Boolean,
    val tags: Optional = Optional.Missing(),
    val flags: RoleFlags,
) {
    public companion object {
        public val description: DataDescription = description(RoleData::id)

        public fun from(guildId: Snowflake, entity: DiscordRole): RoleData = with(entity) {
            RoleData(
                id,
                guildId,
                name,
                color,
                hoist,
                icon,
                unicodeEmoji,
                position,
                permissions,
                managed,
                mentionable,
                tags.map { RoleTagsData.from(it) },
                flags,
            )
        }

        public fun from(entity: DiscordGuildRole): RoleData = from(entity.guildId, entity.role)

    }
}

public fun DiscordRole.toData(guildId: Snowflake): RoleData {
    return RoleData.from(DiscordGuildRole(guildId, this))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy