mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
New API draft
This commit is contained in:
+14
-12
@@ -1,31 +1,33 @@
|
||||
import Client from "../module/Client.ts";
|
||||
|
||||
class RequestManager {
|
||||
client: Client
|
||||
token: string
|
||||
client: Client;
|
||||
token: string;
|
||||
currentRatelimit
|
||||
|
||||
constructor(client: Client, token: string) {
|
||||
this.client = client
|
||||
this.token = token
|
||||
}
|
||||
|
||||
async get(url: string, payload?: unknown) {
|
||||
// THIS IS IMPORTANT. It keeps clean stack errors in the users own files to better help debug errors.
|
||||
// const stackHolder = {};
|
||||
// TODO: Figure out why this doesnt work
|
||||
// Error.captureStackTrace(stackHolder)
|
||||
async get(url: string, payload?: unknown, shouldRatelimit = true) {
|
||||
if (shouldRatelimit) {
|
||||
|
||||
// let attempts = 0
|
||||
const headers = {
|
||||
Authorization: this.token,
|
||||
"User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)`,
|
||||
}
|
||||
|
||||
const headers = this.getDiscordHeaders();
|
||||
console.log('payload', payload)
|
||||
|
||||
const data = await fetch(url, { headers }).then(res => res.json())
|
||||
return data
|
||||
}
|
||||
|
||||
// The Record type here plays nice with Deno's `fetch.headers` expected type.
|
||||
getDiscordHeaders (): Record<string, string> {
|
||||
return {
|
||||
Authorization: this.token,
|
||||
"User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default RequestManager
|
||||
Reference in New Issue
Block a user