Skip to content

Commit

Permalink
Merge branch '0.7.x' of https://github.com/kordlib/kord into 0.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
BartArys committed Dec 4, 2020
2 parents 9cbc510 + 817124e commit 5ab84fe
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions gateway/src/main/kotlin/DefaultGateway.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class DefaultGateway(private val data: DefaultGatewayData) : Gateway {

private val jsonParser = Json {
ignoreUnknownKeys = true
isLenient = true
}

private val stateMutex = Mutex()
Expand Down
11 changes: 9 additions & 2 deletions gateway/src/main/kotlin/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ sealed class Event {
}


@OptIn(ExperimentalSerializationApi::class)
private fun getByDispatchEvent(index: Int, decoder: CompositeDecoder, name: String?, sequence: Int?) = when (name) {
"PRESENCES_REPLACE" -> null //https://github.com/kordlib/kord/issues/42
"RESUMED" -> Resumed(sequence)
"PRESENCES_REPLACE" -> {
decoder.decodeNullableSerializableElement(descriptor, index, JsonElement.serializer().nullable)
null //https://github.com/kordlib/kord/issues/42
}
"RESUMED" -> {
decoder.decodeNullableSerializableElement(descriptor, index, JsonElement.serializer().nullable)
Resumed(sequence)
}
"READY" -> Ready(decoder.decodeSerializableElement(descriptor, index, ReadyData.serializer()), sequence)
"CHANNEL_CREATE" -> ChannelCreate(decoder.decodeSerializableElement(descriptor, index, DiscordChannel.serializer()), sequence)
"CHANNEL_UPDATE" -> ChannelUpdate(decoder.decodeSerializableElement(descriptor, index, DiscordChannel.serializer()), sequence)
Expand Down
17 changes: 16 additions & 1 deletion gateway/src/test/kotlin/json/RegressionTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ class RegressionTests {
event shouldBe Reconnect
}

}
@Test
fun `Resumed with unknown data`(){
Json.decodeFromString(Event.Companion, file("resumeWithUnknownData"))
}

@Test
fun `PresenceReplace with unknown data`(){
Json.decodeFromString(Event.Companion, file("presenceReplaceWithUnknownData"))
}

@Test
fun `Unknown event with successfully parses`(){
Json.decodeFromString(Event.Companion, file("eventWithUnknownData")) //dispatch event with non-existent type
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"t": "DOCUMENTED_API",
"s": 30,
"op": 0,
"d": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"t": "PRESENCES_REPLACE",
"s": 1337,
"op": 0,
"d": {
"some" : "key"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"t": "RESUMED",
"s": 30,
"op": 0,
"d": {
"_trace": [
"[\"gateway-prd-main-dj3z\",{\"micros\":1542,\"calls\":[\"discord-sessions-prd-2-122\",{\"micros\":16}]}]"
]
}
}

0 comments on commit 5ab84fe

Please sign in to comment.