mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
get properly handled with request manager
This commit is contained in:
Vendored
+1
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"deno.autoFmtOnSave": true,
|
||||
"deno.unstable": true
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ export const createClient = async (data: ClientOptions) => {
|
||||
authorization = `Bot ${data.token}`;
|
||||
|
||||
// Initial API connection to get info about bots connection
|
||||
botGatewayData = await RequestManager.get(endpoints.GATEWAY_BOT);
|
||||
botGatewayData = await RequestManager.get(endpoints.GATEWAY_BOT) as DiscordBotGatewayData;
|
||||
|
||||
identifyPayload.token = data.token;
|
||||
identifyPayload.intents = data.intents.reduce(
|
||||
|
||||
@@ -41,12 +41,7 @@ processRateLimitedPaths();
|
||||
export const RequestManager = {
|
||||
// Something off about using runMethod with get breaks when using fetch
|
||||
get: async (url: string, body?: unknown) => {
|
||||
await checkRatelimits(url);
|
||||
const result = await fetch(url, createRequestBody(body));
|
||||
handleStatusCode(result.status);
|
||||
processHeaders(url, result.headers);
|
||||
|
||||
return result.json();
|
||||
return runMethod(RequestMethod.Get, url, body)
|
||||
},
|
||||
post: (url: string, body?: unknown) => {
|
||||
return runMethod(RequestMethod.Post, url, body);
|
||||
@@ -62,7 +57,7 @@ export const RequestManager = {
|
||||
},
|
||||
};
|
||||
|
||||
function createRequestBody(body: any, method?: RequestMethod) {
|
||||
function createRequestBody(body: any, method: RequestMethod) {
|
||||
return {
|
||||
headers: {
|
||||
Authorization: authorization,
|
||||
@@ -72,7 +67,7 @@ function createRequestBody(body: any, method?: RequestMethod) {
|
||||
"X-Audit-Log-Reason": body ? encodeURIComponent(body.reason) : "",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
method: method?.toUpperCase(),
|
||||
method: method.toUpperCase(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ export function createChannel(data: ChannelCreatePayload) {
|
||||
}
|
||||
const result = await RequestManager.get(
|
||||
endpoints.CHANNEL_MESSAGE(data.id, id),
|
||||
);
|
||||
) as MessageCreateOptions;
|
||||
return createMessage(result);
|
||||
},
|
||||
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
|
||||
Reference in New Issue
Block a user