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

@ -62,12 +62,12 @@
"axios": "1.1", "axios": "1.1",
"chalk": "^4.1.2", "chalk": "^4.1.2",
"discord-api-types": "^0.37.40", "discord-api-types": "^0.37.40",
"fetch-cookie": "^2.1.0",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"json-bigint": "^1.0.0", "json-bigint": "^1.0.0",
"lodash.permutations": "^1.0.0", "lodash.permutations": "^1.0.0",
"node-fetch": "^2.6.9", "node-fetch": "^2.6.9",
"safe-base64": "^2.0.1-0", "safe-base64": "^2.0.1-0",
"set-cookie-parser": "^2.6.0",
"string_decoder": "^1.3.0", "string_decoder": "^1.3.0",
"string-similarity": "^4.0.4", "string-similarity": "^4.0.4",
"ws": "^8.13.0" "ws": "^8.13.0"

View File

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

View File

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

View File

@ -4,7 +4,6 @@ const { setTimeout } = require('node:timers');
const { setTimeout: sleep } = require('node:timers/promises'); const { setTimeout: sleep } = require('node:timers/promises');
const { inspect } = require('util'); const { inspect } = require('util');
const { AsyncQueue } = require('@sapphire/async-queue'); const { AsyncQueue } = require('@sapphire/async-queue');
const parseCookie = require('set-cookie-parser');
const DiscordAPIError = require('./DiscordAPIError'); const DiscordAPIError = require('./DiscordAPIError');
const HTTPError = require('./HTTPError'); const HTTPError = require('./HTTPError');
const RateLimitError = require('./RateLimitError'); const RateLimitError = require('./RateLimitError');
@ -241,22 +240,6 @@ class RequestHandler {
let sublimitTimeout; let sublimitTimeout;
if (res.headers) { 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 serverDate = res.headers.get('date');
const limit = res.headers.get('x-ratelimit-limit'); const limit = res.headers.get('x-ratelimit-limit');
const remaining = res.headers.get('x-ratelimit-remaining'); const remaining = res.headers.get('x-ratelimit-remaining');

4
typings/index.d.ts vendored
View File

@ -981,8 +981,8 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public isReady(): this is Client<true>; public isReady(): this is Client<true>;
/** @deprecated Use {@link Sweepers#sweepMessages} instead */ /** @deprecated Use {@link Sweepers#sweepMessages} instead */
public sweepMessages(lifetime?: number): number; public sweepMessages(lifetime?: number): number;
public customStatusAuto(client?: this): undefined; private customStatusAuto(client?: this): undefined;
public authorizeURL(url: string, options?: object): Promise<undefined>; public authorizeURL(url: string, options?: object): Promise<object>;
public sleep(milliseconds: number): Promise<void> | null; public sleep(milliseconds: number): Promise<void> | null;
private _clearCache(cache: Collection<any, any>): void; private _clearCache(cache: Collection<any, any>): void;
public toJSON(): unknown; public toJSON(): unknown;