commonMain.cache.data.InviteData.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-core-jvm Show documentation
Show all versions of kord-core-jvm Show documentation
Idiomatic Kotlin Wrapper for The Discord API
The newest version!
package dev.kord.core.cache.data
import dev.kord.common.entity.DiscordInvite
import dev.kord.common.entity.DiscordInviteWithMetadata
import dev.kord.common.entity.InviteTargetType
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.*
import dev.kord.common.serialization.DurationInSeconds
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
public sealed interface BaseInviteData {
public val code: String
public val guild: Optional
public val channelId: Snowflake?
public val inviterId: OptionalSnowflake
public val targetType: Optional
public val targetUserId: OptionalSnowflake
public val targetApplication: Optional
public val approximatePresenceCount: OptionalInt
public val approximateMemberCount: OptionalInt
public val expiresAt: Optional
public val guildScheduledEvent: Optional
}
@Serializable
public data class InviteData(
override val code: String,
override val guild: Optional = Optional.Missing(),
override val channelId: Snowflake?,
override val inviterId: OptionalSnowflake = OptionalSnowflake.Missing,
override val targetType: Optional = Optional.Missing(),
override val targetUserId: OptionalSnowflake = OptionalSnowflake.Missing,
override val targetApplication: Optional = Optional.Missing(),
override val approximatePresenceCount: OptionalInt = OptionalInt.Missing,
override val approximateMemberCount: OptionalInt = OptionalInt.Missing,
override val expiresAt: Optional = Optional.Missing(),
override val guildScheduledEvent: Optional = Optional.Missing(),
) : BaseInviteData {
public companion object {
public fun from(entity: DiscordInvite): InviteData = with(entity) {
InviteData(
code,
guild = guild.map { PartialGuildData.from(it) },
channelId = channel?.id,
inviterId = inviter.mapSnowflake { it.id },
targetType,
targetUserId = targetUser.mapSnowflake { it.id },
targetApplication = targetApplication.map { PartialApplicationData.from(it) },
approximatePresenceCount,
approximateMemberCount,
expiresAt,
guildScheduledEvent = guildScheduledEvent.map { GuildScheduledEventData.from(it) },
)
}
}
}
@Serializable
public data class InviteWithMetadataData(
override val code: String,
override val guild: Optional = Optional.Missing(),
override val channelId: Snowflake?,
override val inviterId: OptionalSnowflake = OptionalSnowflake.Missing,
override val targetType: Optional = Optional.Missing(),
override val targetUserId: OptionalSnowflake = OptionalSnowflake.Missing,
override val targetApplication: Optional = Optional.Missing(),
override val approximatePresenceCount: OptionalInt = OptionalInt.Missing,
override val approximateMemberCount: OptionalInt = OptionalInt.Missing,
override val expiresAt: Optional = Optional.Missing(),
override val guildScheduledEvent: Optional = Optional.Missing(),
val uses: Int,
val maxUses: Int,
val maxAge: DurationInSeconds,
val temporary: Boolean,
val createdAt: Instant,
) : BaseInviteData {
public companion object {
public fun from(entity: DiscordInviteWithMetadata): InviteWithMetadataData = with(entity) {
InviteWithMetadataData(
code,
guild = guild.map { PartialGuildData.from(it) },
channelId = channel?.id,
inviterId = inviter.mapSnowflake { it.id },
targetType,
targetUserId = targetUser.mapSnowflake { it.id },
targetApplication = targetApplication.map { PartialApplicationData.from(it) },
approximatePresenceCount,
approximateMemberCount,
expiresAt,
guildScheduledEvent = guildScheduledEvent.map { GuildScheduledEventData.from(it) },
uses,
maxUses,
maxAge,
temporary,
createdAt,
)
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy