commit
e8c3bcb0a0
@ -418,6 +418,26 @@ 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();
|
||||||
|
// There is a better way to code this but it's a temp fix - TheDevYellowy
|
||||||
|
await this.clearCache(this.channels.cache);
|
||||||
|
await this.clearCache(this.guilds.cache);
|
||||||
|
await this.clearCache(this.relationships.cache);
|
||||||
|
await this.clearCache(this.sessions.cache);
|
||||||
|
await this.clearCache(this.users.cache);
|
||||||
|
await this.clearCache(this.voiceStates.cache);
|
||||||
|
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
|
||||||
@ -557,6 +577,7 @@ class Client extends BaseClient {
|
|||||||
this.sweepers.destroy();
|
this.sweepers.destroy();
|
||||||
this.ws.destroy();
|
this.ws.destroy();
|
||||||
this.token = null;
|
this.token = null;
|
||||||
|
this.password = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +591,7 @@ class Client extends BaseClient {
|
|||||||
voip_provider: null,
|
voip_provider: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.destroy();
|
await this.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -752,6 +773,16 @@ class Client extends BaseClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear a cache
|
||||||
|
* @param {Collection} cache The cache to clear
|
||||||
|
*/
|
||||||
|
async clearCache(cache) {
|
||||||
|
await cache.forEach(async (V, K) => {
|
||||||
|
await cache.delete(K);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
||||||
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
||||||
|
8
typings/index.d.ts
vendored
8
typings/index.d.ts
vendored
@ -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>;
|
||||||
@ -925,6 +932,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public customStatusAuto(client?: this): undefined;
|
public customStatusAuto(client?: this): undefined;
|
||||||
public authorizeURL(url: string, options?: object): Promise<boolean>;
|
public authorizeURL(url: string, options?: object): Promise<boolean>;
|
||||||
public sleep(milliseconds: number): Promise<void> | null;
|
public sleep(milliseconds: number): Promise<void> | null;
|
||||||
|
public clearCache(cache: Collection<any, any>): void;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
|
|
||||||
public on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => Awaitable<void>): this;
|
public on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => Awaitable<void>): this;
|
||||||
|
Loading…
Reference in New Issue
Block a user