diff --git a/common/src/main/kotlin/entity/Snowflake.kt b/common/src/main/kotlin/entity/Snowflake.kt index 3593540b095c..187d6e203085 100644 --- a/common/src/main/kotlin/entity/Snowflake.kt +++ b/common/src/main/kotlin/entity/Snowflake.kt @@ -71,7 +71,7 @@ class Snowflake(val value: Long) : Comparable { override fun deserialize(decoder: Decoder): Snowflake = Snowflake(decoder.decodeLong()) override fun serialize(encoder: Encoder, value: Snowflake) { - encoder.encodeLong(value.value) + encoder.encodeString(value.value.toString()) } } } @@ -79,4 +79,4 @@ class Snowflake(val value: Long) : Comparable { private class SnowflakeMark(val epochMilliseconds: Long) : TimeMark() { override fun elapsedNow(): Duration = Instant.fromEpochMilliseconds(epochMilliseconds) - Clock.System.now() -} +} \ No newline at end of file diff --git a/core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt b/core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt index 85f818b6c29d..6a01603a989e 100644 --- a/core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt +++ b/core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt @@ -3,6 +3,7 @@ package dev.kord.core.behavior.channel import dev.kord.common.entity.Snowflake import dev.kord.core.Kord import dev.kord.core.cache.data.ChannelData +import dev.kord.core.entity.channel.VoiceChannel import dev.kord.core.cache.data.StageInstanceData import dev.kord.core.entity.StageInstance import dev.kord.core.entity.channel.Channel @@ -32,7 +33,6 @@ interface StageChannelBehavior : BaseVoiceChannelBehavior { return StageChannelBehavior(id, guildId, kord, strategy.supply(kord)) } - suspend fun createStageInstance(topic: String): StageInstance { val instance = kord.rest.stageInstance.createStageInstance(id, topic) val data = StageInstanceData.from(instance) diff --git a/core/src/main/kotlin/entity/Guild.kt b/core/src/main/kotlin/entity/Guild.kt index 294fc57e93c1..a996240e8e15 100644 --- a/core/src/main/kotlin/entity/Guild.kt +++ b/core/src/main/kotlin/entity/Guild.kt @@ -27,8 +27,8 @@ import dev.kord.core.supplier.getChannelOfOrNull import dev.kord.rest.Image import dev.kord.rest.service.RestClient import kotlinx.coroutines.flow.first -import java.time.Instant -import java.time.format.DateTimeFormatter +import kotlinx.datetime.Instant +import kotlinx.datetime.toInstant import java.util.* /** @@ -182,12 +182,7 @@ class Guild( * The time at which this guild was joined, if present. */ val joinedTime: Instant? - get() = data.joinedAt.value?.let { - DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse( - it, - Instant::from - ) - } + get() = data.joinedAt.value?.toInstant() /** * The id of the owner. diff --git a/core/src/main/kotlin/entity/Message.kt b/core/src/main/kotlin/entity/Message.kt index d7c4c28998e8..96bd7debbfdc 100644 --- a/core/src/main/kotlin/entity/Message.kt +++ b/core/src/main/kotlin/entity/Message.kt @@ -24,8 +24,8 @@ import dev.kord.core.supplier.EntitySupplyStrategy import dev.kord.core.supplier.getChannelOf import dev.kord.core.supplier.getChannelOfOrNull import kotlinx.coroutines.flow.* -import java.time.Instant -import java.time.format.DateTimeFormatter +import kotlinx.datetime.Instant +import kotlinx.datetime.toInstant import java.util.* /** @@ -74,9 +74,7 @@ class Message( * Returns null if the message was never edited. */ val editedTimestamp: Instant? - get() = data.editedTimestamp?.let { - DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(it, Instant::from) - } + get() = data.editedTimestamp?.toInstant() /** * The embedded content of this message. @@ -215,7 +213,7 @@ class Message( /** * The instant when this message was created. */ - val timestamp: Instant get() = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(data.timestamp, Instant::from) + val timestamp: Instant get() = data.timestamp.toInstant() /** * Whether this message was send using `\tts`. diff --git a/core/src/samples/kotlin/PingBot.kt b/core/src/samples/kotlin/PingBot.kt index 2582b8c3b667..048abf4e1b50 100644 --- a/core/src/samples/kotlin/PingBot.kt +++ b/core/src/samples/kotlin/PingBot.kt @@ -1,8 +1,4 @@ import dev.kord.core.Kord -import dev.kord.core.behavior.channel.createStageInstance -import dev.kord.core.behavior.channel.getStageInstance -import dev.kord.core.behavior.getChannelOf -import dev.kord.core.entity.channel.StageChannel import dev.kord.core.event.message.MessageCreateEvent import dev.kord.core.on diff --git a/core/src/test/kotlin/performance/KordEventDropTest.kt b/core/src/test/kotlin/performance/KordEventDropTest.kt index ecc60599727c..19c1aa4dc77c 100644 --- a/core/src/test/kotlin/performance/KordEventDropTest.kt +++ b/core/src/test/kotlin/performance/KordEventDropTest.kt @@ -14,10 +14,10 @@ import dev.kord.rest.request.KtorRequestHandler import dev.kord.rest.service.RestClient import io.ktor.client.* import kotlinx.coroutines.* -import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.flow.* -import java.time.Clock +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.datetime.Clock import java.util.concurrent.CountDownLatch import java.util.concurrent.atomic.AtomicInteger import kotlin.coroutines.CoroutineContext @@ -25,7 +25,6 @@ import kotlin.coroutines.EmptyCoroutineContext import kotlin.test.Test import kotlin.test.assertEquals import kotlin.time.Duration -import kotlin.time.minutes class KordEventDropTest { @@ -47,13 +46,13 @@ class KordEventDropTest { } val kord = Kord( - resources = ClientResources("token", Shards(1), HttpClient(), EntitySupplyStrategy.cache, Intents.none), - cache = DataCache.none(), - MasterGateway(mapOf(0 to SpammyGateway)), - RestClient(KtorRequestHandler("token", clock = Clock.systemUTC())), - Snowflake("420"), - MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE), - Dispatchers.Default + resources = ClientResources("token", Shards(1), HttpClient(), EntitySupplyStrategy.cache, Intents.none), + cache = DataCache.none(), + MasterGateway(mapOf(0 to SpammyGateway)), + RestClient(KtorRequestHandler("token", clock = Clock.System)), + Snowflake("420"), + MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE), + Dispatchers.Default ) @Test @@ -100,7 +99,7 @@ class KordEventDropTest { SpammyGateway.events.emit(event) } - withTimeout(1.minutes) { + withTimeout(Duration.minutes(1).inWholeMilliseconds) { countdown.await() } assertEquals(amount, counter.get()) diff --git a/gateway/src/main/kotlin/builder/PresenceBuilder.kt b/gateway/src/main/kotlin/builder/PresenceBuilder.kt index bcf66338f43d..9b4756036bc6 100644 --- a/gateway/src/main/kotlin/builder/PresenceBuilder.kt +++ b/gateway/src/main/kotlin/builder/PresenceBuilder.kt @@ -7,7 +7,7 @@ import dev.kord.common.entity.DiscordBotActivity import dev.kord.common.entity.optional.Optional import dev.kord.gateway.DiscordPresence import dev.kord.gateway.UpdateStatus -import java.time.Instant +import kotlinx.datetime.Instant @KordDsl class PresenceBuilder { @@ -36,7 +36,7 @@ class PresenceBuilder { game = DiscordBotActivity(name, ActivityType.Competing) } - fun toUpdateStatus(): UpdateStatus = UpdateStatus(since?.toEpochMilli(), game?.let(::listOf).orEmpty(), status, afk) + fun toUpdateStatus(): UpdateStatus = UpdateStatus(since?.toEpochMilliseconds(), game?.let(::listOf).orEmpty(), status, afk) - fun toPresence(): DiscordPresence = DiscordPresence(status, afk, since?.toEpochMilli(), game) + fun toPresence(): DiscordPresence = DiscordPresence(status, afk, since?.toEpochMilliseconds(), game) } \ No newline at end of file diff --git a/gateway/src/test/kotlin/json/CommandTest.kt b/gateway/src/test/kotlin/json/CommandTest.kt index 9d0775392ecc..45562e2233b7 100644 --- a/gateway/src/test/kotlin/json/CommandTest.kt +++ b/gateway/src/test/kotlin/json/CommandTest.kt @@ -14,6 +14,7 @@ import dev.kord.gateway.* import kotlinx.serialization.json.* import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import java.util.* private val json = Json { encodeDefaults = false } @@ -61,7 +62,10 @@ class CommandTest { val query = "test" val limit = 1337 - val request = json.encodeToString(Command.Companion, RequestGuildMembers(Snowflake(guildId), query.optional(), OptionalInt.Value(limit))) + val request = json.encodeToString( + Command.Companion, + RequestGuildMembers(Snowflake(guildId), query.optional(), OptionalInt.Value(limit)) + ) val json = json.encodeToString(JsonObject.serializer(), buildJsonObject { put("op", OpCode.RequestGuildMembers.code) @@ -83,7 +87,10 @@ class CommandTest { val selfMute = true val selfDeaf = false - val status = json.encodeToString(Command.Companion, UpdateVoiceStatus(Snowflake(guildId), Snowflake(channelId), selfMute, selfDeaf)) + val status = json.encodeToString( + Command.Companion, + UpdateVoiceStatus(Snowflake(guildId), Snowflake(channelId), selfMute, selfDeaf) + ) val json = json.encodeToString(JsonObject.serializer(), buildJsonObject { put("op", OpCode.VoiceStateUpdate.code) @@ -112,8 +119,8 @@ class CommandTest { put("op", OpCode.StatusUpdate.code) put("d", buildJsonObject { put("since", since) - put("activities", buildJsonArray { }) - put("status", status.value.toLowerCase()) + put("activities", JsonArray(emptyList())) + put("status", status.value.lowercase(Locale.getDefault())) put("afk", afk) }) }) @@ -133,8 +140,16 @@ class CommandTest { val presence: DiscordPresence? = null val identify = json.encodeToString( - Command.Companion, - Identify(token, properties, compress.optional(), largeThreshold.optionalInt(), shard.optional(), presence.optional().coerceToMissing(), Intents.all) + Command.Companion, + Identify( + token, + properties, + compress.optional(), + largeThreshold.optionalInt(), + shard.optional(), + presence.optional().coerceToMissing(), + Intents.all + ) ) val json = json.encodeToString(JsonObject.serializer(), buildJsonObject {