Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Stage Discovery, stickers in GuildPreview, createTimestamp for Threads #491

Merged
5 changes: 4 additions & 1 deletion common/src/main/kotlin/entity/DiscordChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.OptionalSnowflake
import kotlinx.datetime.Instant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -177,7 +178,9 @@ public data class DiscordThreadMetadata(
@SerialName("auto_archive_duration")
val autoArchiveDuration: ArchiveDuration,
val locked: OptionalBoolean = OptionalBoolean.Missing,
val invitable: OptionalBoolean = OptionalBoolean.Missing
val invitable: OptionalBoolean = OptionalBoolean.Missing,
@SerialName("create_timestamp")
val createTimestamp: Optional<Instant> = Optional.Missing(),
)

@Serializable(with = ArchiveDuration.Serializer::class)
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/kotlin/entity/DiscordGuildPreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public data class DiscordGuildPreview(
val approximateMemberCount: Int,
@SerialName("approximate_presence_count")
val approximatePresenceCount: Int,
val description: String?
val description: String?,
val stickers: List<DiscordMessageSticker>,
)
4 changes: 4 additions & 0 deletions common/src/main/kotlin/entity/DiscordStageInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public data class DiscordStageInstance(
val topic: String,
@SerialName("privacy_level")
val privacyLevel: StageInstancePrivacyLevel,
@Deprecated("Stages are no longer discoverable")
@SerialName("discoverable_disabled")
val discoverableDisabled: Boolean
)
Expand All @@ -39,9 +40,11 @@ public data class DiscordStageInstance(
*/
@Serializable(with = StageInstancePrivacyLevel.Serializer::class)
public sealed class StageInstancePrivacyLevel(public val value: Int) {

/**
* The Stage instance is visible publicly, such as on Stage Discovery.
*/
@Deprecated("Stages are no longer discoverable")
public object Public : StageInstancePrivacyLevel(1)

/**
Expand All @@ -58,6 +61,7 @@ public sealed class StageInstancePrivacyLevel(public val value: Int) {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("StageInstancePrivacyLevel", PrimitiveKind.INT)

override fun deserialize(decoder: Decoder): StageInstancePrivacyLevel {
@Suppress("DEPRECATION")
return when (val value = decoder.decodeInt()) {
1 -> Public
2 -> GuildOnly
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/kotlin/cache/data/ChannelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
Expand Down Expand Up @@ -78,12 +79,13 @@ public data class ThreadMetadataData(
val archiveTimestamp: String,
val autoArchiveDuration: ArchiveDuration,
val locked: OptionalBoolean = OptionalBoolean.Missing,
val invitable: OptionalBoolean = OptionalBoolean.Missing
val invitable: OptionalBoolean = OptionalBoolean.Missing,
val createTimestamp: Optional<Instant> = Optional.Missing(),
) {
public companion object {

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

}
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/kotlin/cache/data/GuildPreviewData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class GuildPreviewData(
public val features: List<GuildFeature>,
public val approximateMemberCount: Int,
public val approximatePresenceCount: Int,
public val description: String? = null
public val description: String? = null,
public val stickers: List<StickerData>,
) {
public companion object {
public fun from(entity: DiscordGuildPreview): GuildPreviewData = with(entity) {
Expand All @@ -30,9 +31,9 @@ public class GuildPreviewData(
features,
approximateMemberCount,
approximatePresenceCount,
description
description,
stickers.map { StickerData.from(it) },
)
}
}

}
10 changes: 7 additions & 3 deletions core/src/main/kotlin/entity/GuildPreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GuildPreview(
get() = data.id

/**
* The name of the guild
* The name of the guild.
*/
public val name: String get() = data.name

Expand All @@ -34,7 +34,7 @@ public class GuildPreview(
public val discoverySplash: String? get() = data.discoverySplash

/**
* Ids of custom guild emojis.
* Custom guild emojis.
*/
public val emojis: Set<GuildEmoji> get() = data.emojis.map { GuildEmoji(it, kord) }.toSet()

Expand All @@ -58,8 +58,12 @@ public class GuildPreview(
*/
public val description: String? get() = data.description

/**
* Custom guild stickers.
*/
public val stickers: Set<Sticker> get() = data.stickers.map { GuildSticker(it, kord) }.toSet()

override fun toString(): String {
return "GuildPreview(data=$data, kord=$kord)"
}

}
10 changes: 9 additions & 1 deletion core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ public class TextChannelThread(
override val kord: Kord,
override val supplier: EntitySupplier = kord.defaultSupplier
) : ThreadChannel {

/**
* Whether this thread is private
* Whether this thread is private.
*/
public val isPrivate: Boolean get() = data.type == ChannelType.PrivateThread

/**
* Whether non-moderators can add other non-moderators to a thread.
*
* This is only applicable to [private][isPrivate] threads and will always be `false` for public threads.
*/
public val isInvitable: Boolean get() = data.threadMetadata.value!!.invitable.discordBoolean

override suspend fun getParent(): TextChannel {
return supplier.getChannelOf(parentId)
}
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/kotlin/entity/channel/thread/ThreadChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface ThreadChannel : GuildMessageChannel, ThreadChannelBehavior {
get() = archiveTimestamp

/**
* timestamp when the thread's archive status was last changed.
* The timestamp when the thread's archive status was last changed.
*/
public val archiveTimestamp: Instant get() = threadData.archiveTimestamp.toInstant()

Expand All @@ -72,6 +72,13 @@ public interface ThreadChannel : GuildMessageChannel, ThreadChannelBehavior {
*/
public val autoArchiveDuration: ArchiveDuration get() = threadData.autoArchiveDuration

/**
* The timestamp when the thread was created.
*
* This is only available for threads created after 2022-01-09.
*/
public val createTimestamp: Instant? get() = threadData.createTimestamp.value

/**
* amount of seconds a user has to wait before sending another message
* bots, users with the permission [Manage Messages][dev.kord.common.entity.Permission.ManageMessages] or
Expand Down