feat: emit event when a request is blocked by a captcha
This commit is contained in:
parent
2cabba79f6
commit
78dad45524
@ -8,7 +8,7 @@ const DiscordAPIError = require('./DiscordAPIError');
|
|||||||
const HTTPError = require('./HTTPError');
|
const HTTPError = require('./HTTPError');
|
||||||
const RateLimitError = require('./RateLimitError');
|
const RateLimitError = require('./RateLimitError');
|
||||||
const {
|
const {
|
||||||
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST },
|
Events: { DEBUG, RATE_LIMIT, INVALID_REQUEST_WARNING, API_RESPONSE, API_REQUEST, CAPTCHA_REQUIRED },
|
||||||
} = require('../util/Constants');
|
} = require('../util/Constants');
|
||||||
|
|
||||||
const cookieFilter = str => {
|
const cookieFilter = str => {
|
||||||
@ -386,6 +386,15 @@ class RequestHandler {
|
|||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await parseResponse(res);
|
data = await parseResponse(res);
|
||||||
|
if (data?.captcha_service) {
|
||||||
|
/**
|
||||||
|
* Emitted when a request is blocked by a captcha
|
||||||
|
* @event Client#captchaRequired
|
||||||
|
* @param {Request} request The request that was blocked
|
||||||
|
* @param {Captcha} data The data returned by Discord
|
||||||
|
*/
|
||||||
|
this.manager.client.emit(CAPTCHA_REQUIRED, request, data);
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
data?.captcha_service &&
|
data?.captcha_service &&
|
||||||
this.manager.client.options.captchaService &&
|
this.manager.client.options.captchaService &&
|
||||||
|
@ -517,6 +517,7 @@ exports.Events = {
|
|||||||
RELATIONSHIP_REMOVE: 'relationshipRemove',
|
RELATIONSHIP_REMOVE: 'relationshipRemove',
|
||||||
RELATIONSHIP_UPDATE: 'relationshipUpdate',
|
RELATIONSHIP_UPDATE: 'relationshipUpdate',
|
||||||
UNHANDLED_PACKET: 'unhandledPacket',
|
UNHANDLED_PACKET: 'unhandledPacket',
|
||||||
|
CAPTCHA_REQUIRED: 'captchaRequired',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@ -4807,6 +4807,7 @@ export interface ClientEvents extends BaseClientEvents {
|
|||||||
relationshipUpdate: [id: Snowflake, type: RelationshipTypes, data: object];
|
relationshipUpdate: [id: Snowflake, type: RelationshipTypes, data: object];
|
||||||
unhandledPacket: [packet: { op: GatewayOpcodes | number; d?: any; s?: number; t?: string }, shard: WebSocketShard];
|
unhandledPacket: [packet: { op: GatewayOpcodes | number; d?: any; s?: number; t?: string }, shard: WebSocketShard];
|
||||||
update: [oldVersion: string, newVersion: string];
|
update: [oldVersion: string, newVersion: string];
|
||||||
|
captchaRequired: [request: Request, captcha: Captcha];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConstantsEvents {
|
export interface ConstantsEvents {
|
||||||
@ -4907,6 +4908,7 @@ export interface ConstantsEvents {
|
|||||||
RELATIONSHIP_REMOVE: 'relationshipRemove';
|
RELATIONSHIP_REMOVE: 'relationshipRemove';
|
||||||
RELATIONSHIP_UPDATE: 'relationshipUpdate';
|
RELATIONSHIP_UPDATE: 'relationshipUpdate';
|
||||||
UNHANDLED_PACKET: 'unhandledPacket';
|
UNHANDLED_PACKET: 'unhandledPacket';
|
||||||
|
CAPTCHA_REQUIRED: 'captchaRequired';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebEmbedOptions {
|
export interface WebEmbedOptions {
|
||||||
|
Loading…
Reference in New Issue
Block a user