DiscordKit: can now get to ready event

This commit is contained in:
2026-03-17 16:37:31 -04:00
parent 29a2b0370b
commit 7506a06d7f
6 changed files with 139 additions and 39 deletions

View File

@@ -3,24 +3,55 @@ import Foundation
import FoundationNetworking
#endif
public struct GetGatewayResponse: Codable {
/// https://discord.com/developers/docs/topics/gateway#gateway-intents
public struct Intents: OptionSet, Sendable {
public var rawValue: UInt32
public static let guilds = Intents(rawValue: 1 << 0)
public static let guildMembers = Intents(rawValue: 1 << 1)
public static let guildModeration = Intents(rawValue: 1 << 2)
public static let guildEmojisAndStickers = Intents(rawValue: 1 << 3)
public static let guildIntegrations = Intents(rawValue: 1 << 4)
public static let guildWebhooks = Intents(rawValue: 1 << 5)
public static let guildInvites = Intents(rawValue: 1 << 6)
public static let guildVoiceStates = Intents(rawValue: 1 << 7)
public static let guildPresences = Intents(rawValue: 1 << 8)
public static let guildMessages = Intents(rawValue: 1 << 9)
public static let guildMessageReactions = Intents(rawValue: 1 << 10)
public static let guildMessageTyping = Intents(rawValue: 1 << 11)
public static let directMessages = Intents(rawValue: 1 << 12)
public static let directMessageReactions = Intents(rawValue: 1 << 13)
public static let directMessageTyping = Intents(rawValue: 1 << 14)
public static let messageContent = Intents(rawValue: 1 << 15)
public static let guildScheduledEvents = Intents(rawValue: 1 << 16)
public static let autoModerationConfiguration = Intents(rawValue: 1 << 20)
public static let autoModerationExecution = Intents(rawValue: 1 << 21)
public static let guildMessagePolls = Intents(rawValue: 1 << 24)
public static let directMessagePolls = Intents(rawValue: 1 << 25)
public init(rawValue: UInt32) {
self.rawValue = rawValue
}
}
public struct GetGatewayResponse: Codable, Sendable {
let url: URL
let shards: Int
let session_start_limit: SessionStartLimit
}
public struct SessionStartLimit: Codable {
public struct SessionStartLimit: Codable, Sendable {
let total: Int
let remaining: Int
let reset_after: Int
let max_concurrency: Int
}
public enum GatewayPayload: Decodable {
public enum GatewayPayload: Decodable, Sendable {
case hello(HelloPayload)
}
public struct GatewayMessage: Decodable {
public struct GatewayMessage: Decodable, Sendable {
let op: Int
let d: GatewayPayload?
let s: Int?
@@ -47,8 +78,16 @@ public struct GatewayMessage: Decodable {
break
}
}
public init(op: Int, d: GatewayPayload?, s: Int?, t: String?) {
self.op = op
self.d = d
self.s = s
self.t = t
}
}
public struct HelloPayload: Codable {
public struct HelloPayload: Codable, Sendable {
let heartbeat_interval: Int
}