From 82e32acebef58a7b3c81e80ff4ba2dc7c8748377 Mon Sep 17 00:00:00 2001 From: Skillz Date: Tue, 25 Feb 2020 23:05:37 -0500 Subject: [PATCH] more fixes --- module/discord-request-manager.ts | 64 +++++++++++++++---------------- structures/channel.ts | 2 +- structures/guild.ts | 4 +- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/module/discord-request-manager.ts b/module/discord-request-manager.ts index 8e32c0640..4edc1f747 100644 --- a/module/discord-request-manager.ts +++ b/module/discord-request-manager.ts @@ -1,45 +1,45 @@ -import Client from "../module/Client.ts"; -import { RequestMethod } from "../types/fetch.ts"; +import Client from "../module/Client.ts" +import { RequestMethod } from "../types/fetch.ts" -type RequestBody = string | Blob | ArrayBufferView | ArrayBuffer | FormData | URLSearchParams | null | undefined; +type RequestBody = string | Blob | ArrayBufferView | ArrayBuffer | FormData | URLSearchParams | null | undefined export default class DiscordDiscordRequestManager { - client: Client; - token: string; + client: Client + token: string constructor(client: Client, token: string) { this.client = client this.token = token } - async get(url: string, body?: RequestBody) { - const headers = this.getDiscordHeaders(); - return fetch(url, { headers, body }).then(res => res.json()) - } + async get(url: string, body?: unknown) { + const headers = this.getDiscordHeaders() + return fetch(url, { headers, body: body ? JSON.stringify(body) : undefined }).then(res => res.json()) + } - async post (url: string, body: RequestBody) { - const headers = this.getDiscordHeaders(); - return fetch(url, { - method: RequestMethod.Post, - headers, - body - }); - } + async post(url: string, body?: unknown) { + const headers = this.getDiscordHeaders() + return fetch(url, { + method: RequestMethod.Post, + headers, + body: body ? JSON.stringify(body) : undefined + }).then(res => res.json()) + } - async delete (url: string, body?: RequestBody) { - const headers = this.getDiscordHeaders(); - return fetch(url, { - method: RequestMethod.Delete, - headers, - body - }); - } + async delete(url: string, body?: RequestBody) { + const headers = this.getDiscordHeaders() + return fetch(url, { + method: RequestMethod.Delete, + headers, + body + }) + } - // The Record type here plays nice with Deno's `fetch.headers` expected type. - getDiscordHeaders (): Record { - return { - Authorization: this.token, - "User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)`, - }; - } + // The Record type here plays nice with Deno's `fetch.headers` expected type. + getDiscordHeaders(): Record { + return { + Authorization: this.token, + "User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)` + } + } } diff --git a/structures/channel.ts b/structures/channel.ts index e3dc58383..693c48987 100644 --- a/structures/channel.ts +++ b/structures/channel.ts @@ -112,7 +112,7 @@ export const create_channel = (data: Channel_Create_Options, client: Client) => `This endpoint only accepts a maximum of 100 messages. Deleting the first 100 message ids provided.` ) } - return client.discordRequestManager.POST(endpoints.CHANNEL_BULK_DELETE(data.id), { + return client.discordRequestManager.post(endpoints.CHANNEL_BULK_DELETE(data.id), { messages: ids.splice(0, 100), reason }) diff --git a/structures/guild.ts b/structures/guild.ts index 6a540de91..cf4ed20ea 100644 --- a/structures/guild.ts +++ b/structures/guild.ts @@ -66,7 +66,7 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => { /** The users in this guild. */ members: new Map(data.members.map(m => [m.user.id, create_member(m, data.id, data.roles, data.owner_id, client)])), /** The channels in the guild */ - channels: new Map(data.channels.map(c => [c.id, create_channel(c, guild, client)])), + channels: new Map(data.channels.map(c => [c.id, create_channel(c, client)])), /** The presences of all the users in the guild. */ presences: new Map(data.presences.map(p => [p.user.id, p])), /** The maximum amount of presences for the guild(the default value, currently 5000 is in effect when null is returned.) */ @@ -279,7 +279,7 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => { } let permissionBits = member.roles().reduce((bits, role_id) => { - const role = guild.roles.get(role_id) + const role = guild.roles().get(role_id) if (!role) return bits bits |= role.permissions()