fix: Cookie handler

fix captcha
This commit is contained in:
Elysia
2023-06-01 18:26:22 +07:00
parent 3763233c38
commit 87fb38c82c
5 changed files with 8 additions and 22 deletions

View File

@@ -944,7 +944,7 @@ class Client extends BaseClient {
* Authorize an application.
* @param {string} url Discord Auth URL
* @param {OAuth2AuthorizeOptions} options Oauth2 options
* @returns {Promise<void>}
* @returns {Promise<Object>}
* @example
* client.authorizeURL(`https://discord.com/api/oauth2/authorize?client_id=botID&permissions=8&scope=applications.commands%20bot`, {
guild_id: "guildID",

View File

@@ -3,8 +3,11 @@
const Buffer = require('node:buffer').Buffer;
const https = require('node:https');
const { setTimeout } = require('node:timers');
const makeFetchCookie = require('fetch-cookie');
const FormData = require('form-data');
const fetch = require('node-fetch');
const fetchOriginal = require('node-fetch');
const fetch = makeFetchCookie(fetchOriginal);
let agent = null;

View File

@@ -4,7 +4,6 @@ const { setTimeout } = require('node:timers');
const { setTimeout: sleep } = require('node:timers/promises');
const { inspect } = require('util');
const { AsyncQueue } = require('@sapphire/async-queue');
const parseCookie = require('set-cookie-parser');
const DiscordAPIError = require('./DiscordAPIError');
const HTTPError = require('./HTTPError');
const RateLimitError = require('./RateLimitError');
@@ -241,22 +240,6 @@ class RequestHandler {
let sublimitTimeout;
if (res.headers) {
const cookie = res.headers.raw()['set-cookie'];
if (cookie && Array.isArray(cookie)) {
const oldCookie = parseCookie((this.manager.client.options.http.headers.Cookie || '').split('; '), {
map: true,
});
const parse = parseCookie(cookie, {
map: true,
});
for (const key in parse) {
oldCookie[key] = parse[key];
}
this.manager.client.options.http.headers.Cookie = Object.entries(oldCookie)
.map(([key, value]) => `${key}=${value.value}`)
.join('; ');
this.manager.client.emit('debug', `[REST] Set new cookie: ${this.manager.client.options.http.headers.Cookie}`);
}
const serverDate = res.headers.get('date');
const limit = res.headers.get('x-ratelimit-limit');
const remaining = res.headers.get('x-ratelimit-remaining');