From 68b3ff4b376b2d88bc47eb996fa7ab72c78c4a52 Mon Sep 17 00:00:00 2001 From: Skillz Date: Wed, 26 Feb 2020 10:10:56 -0500 Subject: [PATCH] all errors fixed --- module/discord-request-manager.ts | 24 +++++++++++++++++++++--- structures/channel.ts | 25 ++++++++++++------------- structures/guild.ts | 2 +- types/guild.ts | 31 +++++++++++++++++++------------ 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/module/discord-request-manager.ts b/module/discord-request-manager.ts index 4edc1f747..d942dec53 100644 --- a/module/discord-request-manager.ts +++ b/module/discord-request-manager.ts @@ -1,7 +1,7 @@ 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 @@ -26,15 +26,33 @@ export default class DiscordDiscordRequestManager { }).then(res => res.json()) } - async delete(url: string, body?: RequestBody) { + async delete(url: string, body?: unknown) { const headers = this.getDiscordHeaders() return fetch(url, { method: RequestMethod.Delete, headers, - body + body: body ? JSON.stringify(body) : undefined }) } + async patch(url: string, body: unknown) { + const headers = this.getDiscordHeaders() + return fetch(url, { + method: RequestMethod.Patch, + headers, + body: body ? JSON.stringify(body) : undefined + }).then(res => res.json()) + } + + async put(url: string, body: unknown) { + const headers = this.getDiscordHeaders() + return fetch(url, { + method: RequestMethod.Put, + headers, + body: body ? JSON.stringify(body) : undefined + }).then(res => res.json()) + } + // The Record type here plays nice with Deno's `fetch.headers` expected type. getDiscordHeaders(): Record { return { diff --git a/structures/channel.ts b/structures/channel.ts index 693c48987..1cabdd106 100644 --- a/structures/channel.ts +++ b/structures/channel.ts @@ -1,5 +1,5 @@ import { - Channel_Create_Options, + Channel_Create_Payload, Channel_Types, Get_Messages_After, Get_Messages_Around, @@ -13,17 +13,23 @@ import { endpoints } from "../constants/discord.ts" import { create_message, Message } from "./message.ts" import { Message_Create_Options } from "../types/message.ts" -export const create_channel = (data: Channel_Create_Options, client: Client) => { +export const create_channel = (data: Channel_Create_Payload, client: Client) => { const base_channel = { + /** The raw channel data */ + raw: () => data, /** The unique id of the channel */ id: data.id, /** The type of the channel. */ type: () => data.type, /** The id of the guild where this channel exists */ - guild_id: () => data.guild_id + guild_id: () => data.guild_id, + // TODO: fix this from being number on allow and deny to being array of strings + /** The permission overwrites for this channel */ + permission_overwrites: () => data.permission_overwrites } const base_text_channel = { + ...base_channel, /** A short collection of recently sent messages since bot started. */ messages: new Map(), /** The last message id in this channel */ @@ -71,12 +77,7 @@ export const create_channel = (data: Channel_Create_Options, client: Client) => } // If it is a dm channel - if (data.type === Channel_Types.DM) { - return { - ...base_channel, - ...base_text_channel - } - } + if (data.type === Channel_Types.DM) return base_text_channel // GUILD CHANNEL ONLY const base_guild_channel = { @@ -86,10 +87,7 @@ export const create_channel = (data: Channel_Create_Options, client: Client) => /** The position of the channel in the server. */ position: () => data.position!, /** The category id for this channel. */ - parent_id: () => data.parent_id, - // TODO: fix this from being number on allow and deny to being array of strings - /** Fetch the permission overwrites */ - permission_overwrites: () => data.permission_overwrites + parent_id: () => data.parent_id } // Guild Text Channel @@ -150,6 +148,7 @@ export const create_channel = (data: Channel_Create_Options, client: Client) => return { ...data, + ...base_channel, /** The channel mention */ mention: () => `<#${data.id}>` } diff --git a/structures/guild.ts b/structures/guild.ts index cf4ed20ea..e3440e5af 100644 --- a/structures/guild.ts +++ b/structures/guild.ts @@ -287,7 +287,7 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => { return bits }, 0) - channel.permission_overwrites?.forEach(overwrite => { + channel.permission_overwrites()?.forEach(overwrite => { permissionBits = (permissionBits & ~overwrite.deny) | overwrite.allow }) diff --git a/types/guild.ts b/types/guild.ts index 8d319751b..cead9f896 100644 --- a/types/guild.ts +++ b/types/guild.ts @@ -1,11 +1,11 @@ -import { Emoji, StatusType } from './discord.ts' -import { User } from '../structures/user.ts' -import { Permission } from './permission.ts' -import { Role_Data } from './role.ts' -import { Member_Create_Payload } from './member.ts' -import { Activity } from './message.ts' -import { ClientStatusPayload } from '../structures/presence.ts' -import { Channel_Create_Options } from './channel.ts' +import { Emoji, StatusType } from "./discord.ts" +import { User } from "../structures/user.ts" +import { Permission } from "./permission.ts" +import { Role_Data } from "./role.ts" +import { Member_Create_Payload } from "./member.ts" +import { Activity } from "./message.ts" +import { ClientStatusPayload } from "../structures/presence.ts" +import { Channel_Create_Payload } from "./channel.ts" export interface Create_Guild_Payload { /** The guild id */ @@ -52,7 +52,7 @@ export interface Create_Guild_Payload { /** Users in the guild */ members: Member_Create_Payload[] /** Channels in the guild */ - channels: Channel_Create_Options[] + channels: Channel_Create_Payload[] presences: Presence[] /** The maximum amount of presences for the guild(the default value, currently 5000 is in effect when null is returned.) */ max_presences?: number | null @@ -183,6 +183,13 @@ export interface Guild_Integration { synced_at: string } +export interface Account { + /** id of the account */ + id: string + /** name of the account */ + name: string +} + export interface User_Data { /** The user's id */ id: string @@ -325,13 +332,13 @@ export enum AuditLogs { INTEGRATION_DELETE } -export type ChannelType = 'text' | 'dm' | 'news' | 'voice' | 'category' | 'store' +export type ChannelType = "text" | "dm" | "news" | "voice" | "category" | "store" export interface Overwrite { /** The role or user id */ id: string /** Whether this is a role or a member */ - type: 'role' | 'member' + type: "role" | "member" /** The permissions that this id is allowed to do. (This will mark it as a green check.) */ allow: Permission[] /** The permissions that this id is NOT allowed to do. (This will mark it as a red x.) */ @@ -342,7 +349,7 @@ export interface Raw_Overwrite { /** The role or user id */ id: string /** Whether this is a role or a member */ - type: 'role' | 'member' + type: "role" | "member" /** The permissions that this id is allowed to do. (This will mark it as a green check.) */ allow: number /** The permissions that this id is NOT allowed to do. (This will mark it as a red x.) */