Skip to content

Commit

Permalink
Make Updatestatus activities not-null
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 committed May 3, 2021
1 parent 69f463e commit b010f92
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gateway/src/main/kotlin/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ data class UpdateVoiceStatus(
@Serializable
data class UpdateStatus(
val since: Long?,
val activities: List<DiscordBotActivity>?,
val activities: List<DiscordBotActivity>,
val status: PresenceStatus,
val afk: Boolean,
) : Command()
2 changes: 1 addition & 1 deletion gateway/src/main/kotlin/builder/PresenceBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PresenceBuilder {
game = DiscordBotActivity(name, ActivityType.Competing)
}

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

fun toPresence(): DiscordPresence = DiscordPresence(status, afk, since?.toEpochMilli(), game)
}
7 changes: 4 additions & 3 deletions gateway/src/test/kotlin/json/CommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package json

import dev.kord.common.entity.DiscordBotActivity
import dev.kord.common.entity.DiscordShard
import dev.kord.common.entity.PresenceStatus
import dev.kord.common.entity.Snowflake
Expand Down Expand Up @@ -101,17 +102,17 @@ class CommandTest {
@Test
fun `UpdateState command serialization`() {
val since = 1242518400L
val game = null
val activities = listOf<DiscordBotActivity>()
val status = PresenceStatus.Online
val afk = false

val updateStatus = json.encodeToString(Command.Companion, UpdateStatus(since, game, status, afk))
val updateStatus = json.encodeToString(Command.Companion, UpdateStatus(since, activities, status, afk))

val json = json.encodeToString(JsonObject.serializer(), buildJsonObject {
put("op", OpCode.StatusUpdate.code)
put("d", buildJsonObject {
put("since", since)
put("activities", null as String?)
put("activities", buildJsonArray { })
put("status", status.value.toLowerCase())
put("afk", afk)
})
Expand Down

0 comments on commit b010f92

Please sign in to comment.