mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
more fixes
This commit is contained in:
@@ -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<string, string> {
|
||||
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<string, string> {
|
||||
return {
|
||||
Authorization: this.token,
|
||||
"User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user