rename DiscordClient to ApiClient
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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<String.SubSequence>,
|
||||
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<String.SubSequence>,
|
||||
client: DiscordClient,
|
||||
client: ApiClient,
|
||||
ctx: MessageCreate
|
||||
) async throws {
|
||||
guard let patRes = patRes else { print("pat.txt not loaded"); return }
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -45,7 +45,7 @@ struct Wolfram {
|
||||
|
||||
static func handleMath(
|
||||
_ args: ArraySlice<String.SubSequence>,
|
||||
client: DiscordClient,
|
||||
client: ApiClient,
|
||||
ctx: MessageCreate
|
||||
) async throws {
|
||||
let typingIndicatorTask = Task {
|
||||
|
||||
Reference in New Issue
Block a user