rename DiscordClient to ApiClient

This commit is contained in:
Andrew Glaze
2026-03-22 13:15:54 -04:00
parent e6426225d7
commit 887f6e46d4
5 changed files with 12 additions and 12 deletions

View File

@@ -4,11 +4,11 @@ import FoundationNetworking
#endif #endif
public actor Bot { public actor Bot {
public let client: DiscordClient public let client: ApiClient
let gateway: GatewayClient let gateway: GatewayClient
public init(token: String, intents: Intents) async throws { public init(token: String, intents: Intents) async throws {
client = DiscordClient(token: token) client = ApiClient(token: token)
let gatewayURL = try await client.getGatewayURL() let gatewayURL = try await client.getGatewayURL()
gateway = GatewayClient(gatewayURL: gatewayURL, token: token, intents: intents) gateway = GatewayClient(gatewayURL: gatewayURL, token: token, intents: intents)
} }

View File

@@ -3,7 +3,7 @@ import Foundation
import FoundationNetworking import FoundationNetworking
#endif #endif
public struct DiscordClient: Sendable { public struct ApiClient: Sendable {
static let apiUrl: URL = URL(string: "https://discord.com/api/v10")! static let apiUrl: URL = URL(string: "https://discord.com/api/v10")!
let token: String let token: String
@@ -20,7 +20,7 @@ public struct DiscordClient: Sendable {
} }
func getGatewayURL() async throws -> URL { 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" req.httpMethod = "GET"
let (data, _) = try await authReq(req) let (data, _) = try await authReq(req)
@@ -30,7 +30,7 @@ public struct DiscordClient: Sendable {
} }
public func getOwnUser() async throws -> User { 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" req.httpMethod = "GET"
let (data, _) = try await authReq(req) let (data, _) = try await authReq(req)
@@ -40,7 +40,7 @@ public struct DiscordClient: Sendable {
} }
public func createMessage(channelId: String, payload: CreateMessageReq) async throws { 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" req.httpMethod = "POST"
let json = JSONEncoder() let json = JSONEncoder()
@@ -49,7 +49,7 @@ public struct DiscordClient: Sendable {
} }
public func triggerTypingIndicator(channelId: String) async throws { 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" req.httpMethod = "POST"
try await authReq(req) try await authReq(req)
} }

View File

@@ -5,7 +5,7 @@ struct Actions {
mention.member?.nick ?? mention.global_name ?? mention.username 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 author = "**\(ctx.member?.nick ?? ctx.author?.global_name ?? ctx.author?.username ?? "Zundamon")**"
let dests = ctx.mentions.map(getUserFromMention).map({ "**\($0)**" }) let dests = ctx.mentions.map(getUserFromMention).map({ "**\($0)**" })
let orig: String let orig: String
@@ -39,7 +39,7 @@ struct Actions {
static func hug( static func hug(
_ args: ArraySlice<String.SubSequence>, _ args: ArraySlice<String.SubSequence>,
client: DiscordClient, client: ApiClient,
ctx: MessageCreate ctx: MessageCreate
) async throws { ) async throws {
guard let hugRes = hugRes else { print("hug.txt not loaded"); return } guard let hugRes = hugRes else { print("hug.txt not loaded"); return }
@@ -98,7 +98,7 @@ struct Actions {
static func pat( static func pat(
_ args: ArraySlice<String.SubSequence>, _ args: ArraySlice<String.SubSequence>,
client: DiscordClient, client: ApiClient,
ctx: MessageCreate ctx: MessageCreate
) async throws { ) async throws {
guard let patRes = patRes else { print("pat.txt not loaded"); return } guard let patRes = patRes else { print("pat.txt not loaded"); return }

View File

@@ -6,7 +6,7 @@ import DiscordKit
struct MessageHandler { struct MessageHandler {
let ctx: MessageCreate let ctx: MessageCreate
let client: DiscordClient let client: ApiClient
static let prefix = ":" static let prefix = ":"
static let zundaGifData = try? Data(contentsOf: URL(filePath: "resources/media/zundamone.gif")) static let zundaGifData = try? Data(contentsOf: URL(filePath: "resources/media/zundamone.gif"))

View File

@@ -45,7 +45,7 @@ struct Wolfram {
static func handleMath( static func handleMath(
_ args: ArraySlice<String.SubSequence>, _ args: ArraySlice<String.SubSequence>,
client: DiscordClient, client: ApiClient,
ctx: MessageCreate ctx: MessageCreate
) async throws { ) async throws {
let typingIndicatorTask = Task { let typingIndicatorTask = Task {