DiscordKit: can receive and decode hello event

This commit is contained in:
2026-03-12 09:35:23 -04:00
parent d42227ba55
commit 707bbedac2
4 changed files with 66 additions and 4 deletions

View File

@@ -15,3 +15,36 @@ public struct SessionStartLimit: Codable {
let reset_after: Int
let max_concurrency: Int
}
public enum GatewayPayload: Decodable {
case hello(HelloPayload)
}
public struct GatewayMessage: Decodable {
let op: Int
let d: GatewayPayload?
enum CodingKeys: String, CodingKey {
case t
case s
case op
case d
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
op = try container.decode(Int.self, forKey: .op)
switch op {
case 10:
let hello = try container.decode(HelloPayload.self, forKey: .d)
d = .hello(hello)
default:
d = nil
break
}
}
}
public struct HelloPayload: Codable {
let heartbeat_interval: Int
}