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

commonMain.cache.data.ChannelData.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.*
import dev.kord.common.serialization.DurationInSeconds
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
public data class ChannelData(
    val id: Snowflake,
    val type: ChannelType,
    val guildId: OptionalSnowflake = OptionalSnowflake.Missing,
    val position: OptionalInt = OptionalInt.Missing,
    val permissionOverwrites: Optional> = Optional.Missing(),
    val name: Optional = Optional.Missing(),
    val topic: Optional = Optional.Missing(),
    val nsfw: OptionalBoolean = OptionalBoolean.Missing,
    val lastMessageId: OptionalSnowflake? = OptionalSnowflake.Missing,
    val bitrate: OptionalInt = OptionalInt.Missing,
    val userLimit: OptionalInt = OptionalInt.Missing,
    val rateLimitPerUser: Optional = Optional.Missing(),
    val recipients: Optional> = Optional.Missing(),
    val icon: Optional = Optional.Missing(),
    val ownerId: OptionalSnowflake = OptionalSnowflake.Missing,
    val applicationId: OptionalSnowflake = OptionalSnowflake.Missing,
    val parentId: OptionalSnowflake? = OptionalSnowflake.Missing,
    val lastPinTimestamp: Optional = Optional.Missing(),
    val rtcRegion: Optional = Optional.Missing(),
    val videoQualityMode: Optional = Optional.Missing(),
    val permissions: Optional = Optional.Missing(),
    val threadMetadata: Optional = Optional.Missing(),
    val messageCount: OptionalInt = OptionalInt.Missing,
    val memberCount: OptionalInt = OptionalInt.Missing,
    val defaultAutoArchiveDuration: Optional = Optional.Missing(),
    val member: Optional = Optional.Missing(),
    val flags: Optional = Optional.Missing(),
    val defaultSortOrder: Optional = Optional.Missing(),
    val totalMessageSent: OptionalInt = OptionalInt.Missing,
    val defaultForumLayout: Optional = Optional.Missing(),
    val availableTags: Optional> = Optional.Missing(),
    val appliedTags: Optional> = Optional.Missing(),
    val defaultReactionEmoji: Optional = Optional.Missing(),
    val defaultThreadRateLimitPerUser: Optional = Optional.Missing(),
    val message: Optional = Optional.Missing()
) {


    public companion object {
        public val description: DataDescription = description(ChannelData::id)

        public fun from(entity: DiscordChannel): ChannelData = with(entity) {
            ChannelData(
                id,
                type,
                guildId,
                position,
                permissionOverwrites,
                name,
                topic,
                nsfw,
                lastMessageId,
                bitrate,
                userLimit,
                rateLimitPerUser,
                recipients.mapList { it.id },
                icon,
                ownerId,
                applicationId,
                parentId,
                lastPinTimestamp,
                rtcRegion,
                videoQualityMode,
                permissions,
                threadMetadata.map { ThreadMetadataData.from(it) },
                messageCount,
                memberCount,
                defaultAutoArchiveDuration,
                member.map { ThreadMemberData.from(it, id) },
                flags,
                defaultSortOrder,
                totalMessageSent,
                defaultForumLayout,
                availableTags,
                appliedTags,
                defaultReactionEmoji,
                defaultThreadRateLimitPerUser,
                message.map { MessageData.from(it) }
            )
        }
    }

}

@Serializable
public data class ThreadMetadataData(
    val archived: Boolean,
    val archiveTimestamp: Instant,
    val autoArchiveDuration: ArchiveDuration,
    val locked: OptionalBoolean = OptionalBoolean.Missing,
    val invitable: OptionalBoolean = OptionalBoolean.Missing,
    val createTimestamp: Optional = Optional.Missing(),
) {

    public companion object {
        public fun from(threadMetadata: DiscordThreadMetadata): ThreadMetadataData = with(threadMetadata) {
            ThreadMetadataData(archived, archiveTimestamp, autoArchiveDuration, locked, invitable, createTimestamp)

        }
    }
}


public fun DiscordChannel.toData(): ChannelData = ChannelData.from(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy