Skip to content

Commit

Permalink
Log and ignore all unexpected opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Mar 18, 2024
1 parent 4229686 commit df37913
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions voice/src/main/kotlin/gateway/VoiceEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.kord.voice.gateway
import dev.kord.common.entity.Snowflake
import dev.kord.voice.EncryptionMode
import dev.kord.voice.SpeakingFlags
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
Expand All @@ -16,6 +17,8 @@ import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.DeserializationStrategy as KDeserializationStrategy

private val jsonLogger = KotlinLogging.logger { }

public sealed class VoiceEvent {
public object DeserializationStrategy : KDeserializationStrategy<VoiceEvent?> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("dev.kord.voice.gateway.Event") {
Expand Down Expand Up @@ -47,11 +50,12 @@ public sealed class VoiceEvent {
// https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection-example-resumed-payload
Resumed
}
OpCode.ClientDisconnect -> null // TODO what should we do with this event?
// OpCodes for Commands, they shouldn't be received
OpCode.Identify, OpCode.SelectProtocol, OpCode.Heartbeat, OpCode.Resume ->
throw IllegalArgumentException("Illegal opcode for voice gateway event: $op")
OpCode.Unknown -> null // TODO should we throw an exception instead?
OpCode.Identify, OpCode.SelectProtocol, OpCode.Heartbeat, OpCode.Resume, OpCode.ClientDisconnect,
OpCode.Unknown,
-> {
jsonLogger.debug { "Unknown voice gateway event with opcode $op : $d" }
null
}
}
}

Expand Down

0 comments on commit df37913

Please sign in to comment.