DiscordKit: can receive and decode hello event
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user