all errors fixed

This commit is contained in:
Skillz
2020-02-26 10:10:56 -05:00
parent 82e32acebe
commit 68b3ff4b37
4 changed files with 53 additions and 29 deletions

View File

@@ -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<string, string> {
return {

View File

@@ -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<string, Message>(),
/** 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}>`
}

View File

@@ -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
})

View File

@@ -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.) */