New API draft

This commit is contained in:
Will Hoskings
2020-02-09 23:00:14 +00:00
parent b2800af61d
commit 2f16b77cc9
11 changed files with 303 additions and 64 deletions
+14 -12
View File
@@ -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