Skip to content

Commit

Permalink
Make Updatestatus activities not-null (#274)
Browse files Browse the repository at this point in the history
As per Discord's documentation: discord/discord-api-docs#2789
  • Loading branch information
BartArys authored and HopeBaron committed Jun 24, 2021
1 parent b6b080e commit 9577ada
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
6 changes: 3 additions & 3 deletions gateway/src/main/kotlin/builder/PresenceBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 kotlinx.datetime.Instant
import java.time.Instant

@KordDsl
class PresenceBuilder {
Expand Down Expand Up @@ -36,7 +36,7 @@ class PresenceBuilder {
game = DiscordBotActivity(name, ActivityType.Competing)
}

fun toUpdateStatus(): UpdateStatus = UpdateStatus(since?.toEpochMilliseconds(), game?.let(::listOf).orEmpty(), status, afk)
fun toUpdateStatus(): UpdateStatus = UpdateStatus(since?.toEpochMilli(), game?.let(::listOf).orEmpty(), status, afk)

fun toPresence(): DiscordPresence = DiscordPresence(status, afk, since?.toEpochMilliseconds(), game)
fun toPresence(): DiscordPresence = DiscordPresence(status, afk, since?.toEpochMilli(), game)
}
33 changes: 9 additions & 24 deletions gateway/src/test/kotlin/json/CommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 }

Expand Down Expand Up @@ -62,15 +61,12 @@ 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)
put("d", buildJsonObject {
put("guild_id", guildId.toLong())
put("guild_id", guildId)
put("query", query)
put("limit", limit)
})
Expand All @@ -87,16 +83,13 @@ 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)
put("d", buildJsonObject {
put("guild_id", guildId.toLong())
put("channel_id", channelId.toLong())
put("guild_id", guildId)
put("channel_id", channelId)
put("self_mute", selfMute)
put("self_deaf", selfDeaf)
})
Expand All @@ -119,8 +112,8 @@ class CommandTest {
put("op", OpCode.StatusUpdate.code)
put("d", buildJsonObject {
put("since", since)
put("activities", JsonArray(emptyList()))
put("status", status.value.lowercase(Locale.getDefault()))
put("activities", buildJsonArray { })
put("status", status.value.toLowerCase())
put("afk", afk)
})
})
Expand All @@ -140,16 +133,8 @@ 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 {
Expand Down

0 comments on commit 9577ada

Please sign in to comment.