feat: switch user

This commit is contained in:
Yellowy 2023-01-18 00:00:13 -07:00
parent 597eb2979c
commit c429e3313a
2 changed files with 22 additions and 2 deletions

View File

@ -418,6 +418,19 @@ class Client extends BaseClient {
} }
} }
/**
* Switch the user
* @param {string | switchUserOptions} options Either the token or an object with the username, password, and mfaCode
*/
async switchUser(options) {
await this.logout();
if (typeof options == 'string') {
await this.login(options);
} else {
await this.normalLogin(options.username, options.password, options.mfaCode);
}
}
/** /**
* Sign in with the QR code on your phone. * Sign in with the QR code on your phone.
* @param {boolean} debug Debug mode * @param {boolean} debug Debug mode

11
typings/index.d.ts vendored
View File

@ -868,6 +868,12 @@ export interface remoteAuthConfrim {
no(): Promise<undefined>; no(): Promise<undefined>;
} }
export interface switchUserOptions {
username: string;
password: string;
mfaCode?: number;
}
export class Client<Ready extends boolean = boolean> extends BaseClient { export class Client<Ready extends boolean = boolean> extends BaseClient {
public constructor(options?: ClientOptions); /* Bug report by Mavri#0001 [721347809667973141] */ public constructor(options?: ClientOptions); /* Bug report by Mavri#0001 [721347809667973141] */
private actions: unknown; private actions: unknown;
@ -915,6 +921,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public generateInvite(options?: InviteGenerationOptions): string; public generateInvite(options?: InviteGenerationOptions): string;
public login(token?: string): Promise<string>; public login(token?: string): Promise<string>;
public normalLogin(username: string, password?: string, mfaCode?: string): Promise<string>; public normalLogin(username: string, password?: string, mfaCode?: string): Promise<string>;
public switchUser(options: string | switchUserOptions): void;
public QRLogin(debug?: boolean): DiscordAuthWebsocket; public QRLogin(debug?: boolean): DiscordAuthWebsocket;
public remoteAuth(url: string, forceAccept?: boolean): Promise<remoteAuthConfrim | undefined>; public remoteAuth(url: string, forceAccept?: boolean): Promise<remoteAuthConfrim | undefined>;
public createToken(): Promise<string>; public createToken(): Promise<string>;
@ -5314,8 +5321,8 @@ export type CacheConstructors = {
// Narrowing the type of `manager.name` doesn't propagate type information to `holds` and the return type. // Narrowing the type of `manager.name` doesn't propagate type information to `holds` and the return type.
export type CacheFactory = ( export type CacheFactory = (
manager: CacheConstructors[keyof Caches], manager: CacheConstructors[keyof Caches],
holds: Caches[typeof manager['name']][1], holds: Caches[(typeof manager)['name']][1],
) => typeof manager['prototype'] extends DataManager<infer K, infer V, any> ? Collection<K, V> : never; ) => (typeof manager)['prototype'] extends DataManager<infer K, infer V, any> ? Collection<K, V> : never;
export type CacheWithLimitsOptions = { export type CacheWithLimitsOptions = {
[K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager<infer K, infer V, any> [K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager<infer K, infer V, any>