feat: mfa request

This commit is contained in:
Elysia 2024-01-26 23:12:40 +07:00
parent e8c2b967c3
commit f8a9641d76
2 changed files with 27 additions and 0 deletions

View File

@ -106,6 +106,9 @@ class APIRequest {
'base64', 'base64',
); );
} }
if (this.options.mfaToken) {
headers['X-Discord-Mfa-Authorization'] = this.options.mfaToken;
}
let body; let body;
if (this.options.files?.length) { if (this.options.files?.length) {

View File

@ -355,6 +355,7 @@ class RequestHandler {
let data; let data;
try { try {
data = await parseResponse(res); data = await parseResponse(res);
// Captcha
if ( if (
data?.captcha_service && data?.captcha_service &&
typeof this.manager.client.options.captchaSolver == 'function' && typeof this.manager.client.options.captchaSolver == 'function' &&
@ -384,6 +385,29 @@ class RequestHandler {
request.retries++; request.retries++;
return this.execute(request, captcha, data.captcha_rqtoken); return this.execute(request, captcha, data.captcha_rqtoken);
} }
// Two factor
if (data?.code && data.code == 60003 && request.options.mfaCode && request.retries < 1) {
this.manager.client.emit(
DEBUG,
`${data.message}
Method : ${request.method}
Path : ${request.path}
Route : ${request.route}
mfaCode : ${request.options.mfaCode}`,
);
// Get ticket
const mfaData = data.mfa;
const mfaPost = await this.manager.client.api.mfa.finish.post({
data: {
ticket: mfaData.ticket,
data: request.options.mfaCode,
mfa_type: 'totp',
},
});
request.options.mfaToken = mfaPost.token;
request.retries++;
return this.execute(request);
}
} catch (err) { } catch (err) {
throw new HTTPError(err.message, err.constructor.name, err.status, request); throw new HTTPError(err.message, err.constructor.name, err.status, request);
} }