feat: add email and password login to client

This commit is contained in:
TheDevYellowy 2024-03-26 22:51:17 -05:00
parent 90085a99ce
commit d7fc839e80
3 changed files with 101 additions and 67 deletions

File diff suppressed because one or more lines are too long

View File

@ -277,6 +277,39 @@ class Client extends BaseClient {
return ws.connect(this); return ws.connect(this);
} }
/**
* Logs the client in, establishing a WebSocket connection to Discord.
* @param {string} email The email associated with the account
* @param {string} password The password assicated with the account
* @param {string | number} [code = null] The mfa code if you have it enabled
* @returns {string | null} Token of the account used
*
* @example
* client.passLogin("test@gmail.com", "SuperSecretPa$$word", 1234)
*/
async passLogin(email, password, code = null) {
const initial = await this.api.auth.login.post({
auth: false,
versioned: true,
data: { gift_code_sku_id: null, login_source: null, undelete: false, login: email, password },
});
if ('token' in initial) {
return this.login(initial.token);
} else if ('ticket' in initial) {
const totp = await this.api.auth.mfa.totp.post({
auth: false,
versioned: true,
data: { gift_code_sku_id: null, login_source: null, code, ticket: initial.ticket },
});
if ('token' in totp) {
return this.login(totp.token);
}
}
return null;
}
/** /**
* Returns whether the client has logged in, indicative of being able to access * Returns whether the client has logged in, indicative of being able to access
* properties such as `user` and `application`. * properties such as `user` and `application`.

1
typings/index.d.ts vendored
View File

@ -770,6 +770,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>; public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>;
public sleep(timeout: number): Promise<void>; public sleep(timeout: number): Promise<void>;
public login(token?: string): Promise<string>; public login(token?: string): Promise<string>;
public passLogin(email: string, password: string, code?: string | number): Promise<string | null>;
public QRLogin(): Promise<void>; public QRLogin(): Promise<void>;
public logout(): Promise<void>; public logout(): Promise<void>;
public isReady(): this is Client<true>; public isReady(): this is Client<true>;