diff --git a/Sources/DiscordKit/Bot.swift b/Sources/DiscordKit/Bot.swift index 3877309..0e392a5 100644 --- a/Sources/DiscordKit/Bot.swift +++ b/Sources/DiscordKit/Bot.swift @@ -4,11 +4,11 @@ import FoundationNetworking #endif public actor Bot { - public let client: DiscordClient + public let client: ApiClient let gateway: GatewayClient public init(token: String, intents: Intents) async throws { - client = DiscordClient(token: token) + client = ApiClient(token: token) let gatewayURL = try await client.getGatewayURL() gateway = GatewayClient(gatewayURL: gatewayURL, token: token, intents: intents) } diff --git a/Sources/DiscordKit/DiscordClient.swift b/Sources/DiscordKit/DiscordClient.swift index 4eaf29c..b1ba5d3 100644 --- a/Sources/DiscordKit/DiscordClient.swift +++ b/Sources/DiscordKit/DiscordClient.swift @@ -3,7 +3,7 @@ import Foundation import FoundationNetworking #endif -public struct DiscordClient: Sendable { +public struct ApiClient: Sendable { static let apiUrl: URL = URL(string: "https://discord.com/api/v10")! let token: String @@ -20,7 +20,7 @@ public struct DiscordClient: Sendable { } func getGatewayURL() async throws -> URL { - var req = URLRequest(url: DiscordClient.apiUrl.appending(path: "/gateway/bot")) + var req = URLRequest(url: ApiClient.apiUrl.appending(path: "/gateway/bot")) req.httpMethod = "GET" let (data, _) = try await authReq(req) @@ -30,7 +30,7 @@ public struct DiscordClient: Sendable { } public func getOwnUser() async throws -> User { - var req = URLRequest(url: DiscordClient.apiUrl.appending(path: "/users/@me")) + var req = URLRequest(url: ApiClient.apiUrl.appending(path: "/users/@me")) req.httpMethod = "GET" let (data, _) = try await authReq(req) @@ -40,7 +40,7 @@ public struct DiscordClient: Sendable { } public func createMessage(channelId: String, payload: CreateMessageReq) async throws { - var req = URLRequest(url: DiscordClient.apiUrl.appending(path: "/channels/\(channelId)/messages")) + var req = URLRequest(url: ApiClient.apiUrl.appending(path: "/channels/\(channelId)/messages")) req.httpMethod = "POST" let json = JSONEncoder() @@ -49,7 +49,7 @@ public struct DiscordClient: Sendable { } public func triggerTypingIndicator(channelId: String) async throws { - var req = URLRequest(url: DiscordClient.apiUrl.appending(path: "/channels/\(channelId)/typing")) + var req = URLRequest(url: ApiClient.apiUrl.appending(path: "/channels/\(channelId)/typing")) req.httpMethod = "POST" try await authReq(req) } diff --git a/Sources/zundamon/Actions.swift b/Sources/zundamon/Actions.swift index 5833a22..388ff01 100644 --- a/Sources/zundamon/Actions.swift +++ b/Sources/zundamon/Actions.swift @@ -5,7 +5,7 @@ struct Actions { mention.member?.nick ?? mention.global_name ?? mention.username } - static func performAction(ctx: MessageCreate, client: DiscordClient, resOpts: [String]) async throws { + static func performAction(ctx: MessageCreate, client: ApiClient, resOpts: [String]) async throws { let author = "**\(ctx.member?.nick ?? ctx.author?.global_name ?? ctx.author?.username ?? "Zundamon")**" let dests = ctx.mentions.map(getUserFromMention).map({ "**\($0)**" }) let orig: String @@ -39,7 +39,7 @@ struct Actions { static func hug( _ args: ArraySlice, - client: DiscordClient, + client: ApiClient, ctx: MessageCreate ) async throws { guard let hugRes = hugRes else { print("hug.txt not loaded"); return } @@ -98,7 +98,7 @@ struct Actions { static func pat( _ args: ArraySlice, - client: DiscordClient, + client: ApiClient, ctx: MessageCreate ) async throws { guard let patRes = patRes else { print("pat.txt not loaded"); return } diff --git a/Sources/zundamon/MessageHandler.swift b/Sources/zundamon/MessageHandler.swift index 594f0e8..7ac542e 100644 --- a/Sources/zundamon/MessageHandler.swift +++ b/Sources/zundamon/MessageHandler.swift @@ -6,7 +6,7 @@ import DiscordKit struct MessageHandler { let ctx: MessageCreate - let client: DiscordClient + let client: ApiClient static let prefix = ":" static let zundaGifData = try? Data(contentsOf: URL(filePath: "resources/media/zundamone.gif")) diff --git a/Sources/zundamon/Wolfram.swift b/Sources/zundamon/Wolfram.swift index 5b8fa6f..7b2752d 100644 --- a/Sources/zundamon/Wolfram.swift +++ b/Sources/zundamon/Wolfram.swift @@ -45,7 +45,7 @@ struct Wolfram { static func handleMath( _ args: ArraySlice, - client: DiscordClient, + client: ApiClient, ctx: MessageCreate ) async throws { let typingIndicatorTask = Task {