Image attach
This commit is contained in:
@@ -7,6 +7,7 @@ public struct DiscordClient: Sendable {
|
||||
static let apiUrl: URL = URL(string: "https://discord.com/api/v10")!
|
||||
let token: String
|
||||
|
||||
@discardableResult
|
||||
private func authReq(_ request: consuming URLRequest) async throws -> (Data, URLResponse) {
|
||||
request.setValue("Bot \(token)", forHTTPHeaderField: "Authorization")
|
||||
request.setValue("DiscordKit (https:\\candy123.moe, v0.0.1)", forHTTPHeaderField: "User-Agent")
|
||||
@@ -44,8 +45,7 @@ public struct DiscordClient: Sendable {
|
||||
let json = JSONEncoder()
|
||||
|
||||
req.httpBody = try json.encode(payload)
|
||||
let (data, res) = try await authReq(req)
|
||||
|
||||
try await authReq(req)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,6 @@ actor GatewayClient {
|
||||
}
|
||||
|
||||
try await sendIdentify(intents: intents)
|
||||
//dump(try await getMessage())
|
||||
//print("got here")
|
||||
_ = await heartbeatTask.result
|
||||
}
|
||||
|
||||
|
||||
@@ -96,13 +96,57 @@ public struct GatewayHello: Codable, Sendable {
|
||||
}
|
||||
|
||||
public struct CreateMessageReq: Codable, Sendable {
|
||||
public init(content: String? = nil, message_reference: MessageRefrence? = nil) {
|
||||
public init(content: String? = nil, message_reference: MessageRefrence? = nil, embeds: [Embed]? = nil, files: [RawFile]? = nil, attachments: [Attachment]? = nil) {
|
||||
self.content = content
|
||||
self.message_reference = message_reference
|
||||
self.embeds = embeds
|
||||
self.files = files
|
||||
self.attachments = attachments
|
||||
}
|
||||
|
||||
public let content: String?
|
||||
public let message_reference: MessageRefrence?
|
||||
public let embeds: [Embed]?
|
||||
public let files: [RawFile]?
|
||||
public let attachments: [Attachment]?
|
||||
}
|
||||
|
||||
public struct Attachment: Codable, Sendable {
|
||||
public init(index: Int, filename: String? = nil) {
|
||||
self.index = index
|
||||
self.filename = filename
|
||||
}
|
||||
|
||||
public let index: Int
|
||||
public let filename: String?
|
||||
}
|
||||
|
||||
public struct RawFile: Codable, Sendable {
|
||||
public init(data: Data, filename: String? = nil) {
|
||||
self.data = data
|
||||
self.filename = filename
|
||||
}
|
||||
|
||||
public let data: Data
|
||||
public let filename: String?
|
||||
}
|
||||
|
||||
public struct Embed: Codable, Sendable {
|
||||
public init(description: String? = nil, image: EmbedImage? = nil) {
|
||||
self.description = description
|
||||
self.image = image
|
||||
}
|
||||
|
||||
public let description: String?
|
||||
public let image: EmbedImage?
|
||||
}
|
||||
|
||||
public struct EmbedImage: Codable, Sendable {
|
||||
public init(url: String) {
|
||||
self.url = url
|
||||
}
|
||||
|
||||
public let url: String
|
||||
}
|
||||
|
||||
public struct MessageRefrence: Codable, Sendable {
|
||||
@@ -125,12 +169,28 @@ public struct MessageCreate: Codable, Sendable {
|
||||
public let guild_id: String?
|
||||
public let author: User?
|
||||
public let content: String
|
||||
public let mentions: [User]
|
||||
public let mentions: [MentionUser]
|
||||
public let member: GuildMember?
|
||||
}
|
||||
|
||||
|
||||
public struct User: Codable, Sendable {
|
||||
public let id: String?
|
||||
public let bot: Bool?
|
||||
public let global_name: String?
|
||||
public let username: String
|
||||
}
|
||||
|
||||
public struct GuildMember: Codable, Sendable {
|
||||
public let user: User?
|
||||
public let nick: String?
|
||||
}
|
||||
|
||||
public struct MentionUser: Codable, Sendable {
|
||||
public let id: String?
|
||||
public let bot: Bool?
|
||||
public let global_name: String?
|
||||
public let username: String
|
||||
public let member: GuildMember?
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user