feat: add email and password login to client
This commit is contained in:
parent
90085a99ce
commit
d7fc839e80
File diff suppressed because one or more lines are too long
@ -277,6 +277,39 @@ class Client extends BaseClient {
|
||||
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
|
||||
* properties such as `user` and `application`.
|
||||
|
21
typings/index.d.ts
vendored
21
typings/index.d.ts
vendored
@ -770,6 +770,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>;
|
||||
public sleep(timeout: number): Promise<void>;
|
||||
public login(token?: string): Promise<string>;
|
||||
public passLogin(email: string, password: string, code?: string | number): Promise<string | null>;
|
||||
public QRLogin(): Promise<void>;
|
||||
public logout(): Promise<void>;
|
||||
public isReady(): this is Client<true>;
|
||||
@ -1548,7 +1549,7 @@ export class HTTPError extends Error {
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface - Merge RateLimitData into RateLimitError to not have to type it again
|
||||
export interface RateLimitError extends RateLimitData { }
|
||||
export interface RateLimitError extends RateLimitData {}
|
||||
export class RateLimitError extends Error {
|
||||
private constructor(data: RateLimitData);
|
||||
public name: 'RateLimitError';
|
||||
@ -4903,9 +4904,9 @@ export interface AutoModerationRuleCreateOptions {
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface AutoModerationRuleEditOptions extends Partial<Omit<AutoModerationRuleCreateOptions, 'triggerType'>> { }
|
||||
export interface AutoModerationRuleEditOptions extends Partial<Omit<AutoModerationRuleCreateOptions, 'triggerType'>> {}
|
||||
|
||||
export interface AutoModerationTriggerMetadataOptions extends Partial<AutoModerationTriggerMetadata> { }
|
||||
export interface AutoModerationTriggerMetadataOptions extends Partial<AutoModerationTriggerMetadata> {}
|
||||
|
||||
export interface AutoModerationActionOptions {
|
||||
type: AutoModerationActionType | AutoModerationActionTypes;
|
||||
@ -5974,8 +5975,8 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
|
||||
INVITE: Invite;
|
||||
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
|
||||
INTEGRATION: Integration;
|
||||
CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake;[x: string]: unknown };
|
||||
THREAD: ThreadChannel | { id: Snowflake;[x: string]: unknown };
|
||||
CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown };
|
||||
THREAD: ThreadChannel | { id: Snowflake; [x: string]: unknown };
|
||||
STAGE_INSTANCE: StageInstance;
|
||||
STICKER: Sticker;
|
||||
GUILD_SCHEDULED_EVENT: GuildScheduledEvent;
|
||||
@ -6818,18 +6819,18 @@ export type Partialize<
|
||||
partial: true;
|
||||
} & {
|
||||
[K in keyof Omit<T, 'client' | 'id' | 'partial' | E>]: K extends N ? null : K extends M ? T[K] | null : T[K];
|
||||
};
|
||||
};
|
||||
|
||||
export interface PartialDMChannel extends Partialize<DMChannel, null, null, 'lastMessageId'> {
|
||||
lastMessageId: undefined;
|
||||
}
|
||||
|
||||
export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> { }
|
||||
export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> {}
|
||||
|
||||
export interface PartialMessage
|
||||
extends Partialize<Message, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> { }
|
||||
extends Partialize<Message, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {}
|
||||
|
||||
export interface PartialMessageReaction extends Partialize<MessageReaction, 'count'> { }
|
||||
export interface PartialMessageReaction extends Partialize<MessageReaction, 'count'> {}
|
||||
|
||||
export interface PartialOverwriteData {
|
||||
id: Snowflake | number;
|
||||
@ -6844,7 +6845,7 @@ export interface PartialRoleData extends RoleData {
|
||||
|
||||
export type PartialTypes = 'USER' | 'CHANNEL' | 'GUILD_MEMBER' | 'MESSAGE' | 'REACTION' | 'GUILD_SCHEDULED_EVENT';
|
||||
|
||||
export interface PartialUser extends Partialize<User, 'username' | 'tag' | 'discriminator'> { }
|
||||
export interface PartialUser extends Partialize<User, 'username' | 'tag' | 'discriminator'> {}
|
||||
|
||||
export type PresenceStatusData = ClientPresenceStatus | 'invisible';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user