Merge pull request #1111 from TheDevYellowy/main
feat: add email and password login to client
This commit is contained in:
commit
20241ade25
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`.
|
||||
|
133
typings/index.d.ts
vendored
133
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>;
|
||||
@ -1282,16 +1283,16 @@ export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
|
||||
export class GuildAuditLogsEntry<
|
||||
TActionRaw extends GuildAuditLogsResolvable = 'ALL',
|
||||
TAction = TActionRaw extends keyof GuildAuditLogsIds
|
||||
? GuildAuditLogsIds[TActionRaw]
|
||||
: TActionRaw extends null
|
||||
? 'ALL'
|
||||
: TActionRaw,
|
||||
? GuildAuditLogsIds[TActionRaw]
|
||||
: TActionRaw extends null
|
||||
? 'ALL'
|
||||
: TActionRaw,
|
||||
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
|
||||
? GuildAuditLogsTypes[TAction][1]
|
||||
: 'ALL',
|
||||
? GuildAuditLogsTypes[TAction][1]
|
||||
: 'ALL',
|
||||
TTargetType extends GuildAuditLogsTarget = TAction extends keyof GuildAuditLogsTypes
|
||||
? GuildAuditLogsTypes[TAction][0]
|
||||
: 'UNKNOWN',
|
||||
? GuildAuditLogsTypes[TAction][0]
|
||||
: 'UNKNOWN',
|
||||
> {
|
||||
private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs);
|
||||
public action: TAction;
|
||||
@ -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';
|
||||
@ -1892,8 +1893,8 @@ export class MessageActionRow<
|
||||
T extends MessageActionRowComponent | ModalActionRowComponent = MessageActionRowComponent,
|
||||
U = T extends ModalActionRowComponent ? ModalActionRowComponentResolvable : MessageActionRowComponentResolvable,
|
||||
V = T extends ModalActionRowComponent
|
||||
? APIActionRowComponent<APIModalActionRowComponent>
|
||||
: APIActionRowComponent<APIMessageActionRowComponent>,
|
||||
? APIActionRowComponent<APIModalActionRowComponent>
|
||||
: APIActionRowComponent<APIMessageActionRowComponent>,
|
||||
> extends BaseMessageComponent {
|
||||
// tslint:disable-next-line:ban-ts-ignore
|
||||
// @ts-ignore (TS:2344, Caused by TypeScript 4.8)
|
||||
@ -3683,13 +3684,13 @@ export class ApplicationCommandPermissionsManager<
|
||||
public remove(
|
||||
options:
|
||||
| (FetchSingleOptions & {
|
||||
users: UserResolvable | UserResolvable[];
|
||||
roles?: RoleResolvable | RoleResolvable[];
|
||||
})
|
||||
users: UserResolvable | UserResolvable[];
|
||||
roles?: RoleResolvable | RoleResolvable[];
|
||||
})
|
||||
| (FetchSingleOptions & {
|
||||
users?: UserResolvable | UserResolvable[];
|
||||
roles: RoleResolvable | RoleResolvable[];
|
||||
}),
|
||||
users?: UserResolvable | UserResolvable[];
|
||||
roles: RoleResolvable | RoleResolvable[];
|
||||
}),
|
||||
): Promise<ApplicationCommandPermissions[]>;
|
||||
public set(
|
||||
options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] },
|
||||
@ -4626,12 +4627,12 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
|
||||
|
||||
export interface ApplicationCommandAutocompleteOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
|
||||
type:
|
||||
| 'STRING'
|
||||
| 'NUMBER'
|
||||
| 'INTEGER'
|
||||
| ApplicationCommandOptionTypes.STRING
|
||||
| ApplicationCommandOptionTypes.NUMBER
|
||||
| ApplicationCommandOptionTypes.INTEGER;
|
||||
| 'STRING'
|
||||
| 'NUMBER'
|
||||
| 'INTEGER'
|
||||
| ApplicationCommandOptionTypes.STRING
|
||||
| ApplicationCommandOptionTypes.NUMBER
|
||||
| ApplicationCommandOptionTypes.INTEGER;
|
||||
autocomplete: true;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -5012,8 +5013,8 @@ export type CacheFactory = (
|
||||
|
||||
export type CacheWithLimitsOptions = {
|
||||
[K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager<infer K, infer V, any>
|
||||
? LimitedCollectionOptions<K, V> | number
|
||||
: never;
|
||||
? LimitedCollectionOptions<K, V> | number
|
||||
: never;
|
||||
};
|
||||
export interface CategoryCreateChannelOptions {
|
||||
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
|
||||
@ -5366,12 +5367,12 @@ export interface ConstantsClientApplicationAssetTypes {
|
||||
export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & {
|
||||
focused: true;
|
||||
type:
|
||||
| 'STRING'
|
||||
| 'INTEGER'
|
||||
| 'NUMBER'
|
||||
| ApplicationCommandOptionTypes.STRING
|
||||
| ApplicationCommandOptionTypes.INTEGER
|
||||
| ApplicationCommandOptionTypes.NUMBER;
|
||||
| 'STRING'
|
||||
| 'INTEGER'
|
||||
| 'NUMBER'
|
||||
| ApplicationCommandOptionTypes.STRING
|
||||
| ApplicationCommandOptionTypes.INTEGER
|
||||
| ApplicationCommandOptionTypes.NUMBER;
|
||||
value: string;
|
||||
};
|
||||
|
||||
@ -5930,20 +5931,20 @@ export interface GuildAuditLogsEntryExtraField {
|
||||
MESSAGE_UNPIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
|
||||
MEMBER_DISCONNECT: { count: number };
|
||||
CHANNEL_OVERWRITE_CREATE:
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
CHANNEL_OVERWRITE_UPDATE:
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
CHANNEL_OVERWRITE_DELETE:
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
| Role
|
||||
| GuildMember
|
||||
| { id: Snowflake; name: string; type: OverwriteTypes.role }
|
||||
| { id: Snowflake; type: OverwriteTypes.member };
|
||||
STAGE_INSTANCE_CREATE: StageChannel | { id: Snowflake };
|
||||
STAGE_INSTANCE_DELETE: StageChannel | { id: Snowflake };
|
||||
STAGE_INSTANCE_UPDATE: StageChannel | { id: Snowflake };
|
||||
@ -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;
|
||||
@ -6213,8 +6214,8 @@ export type GuildScheduledEventManagerFetchResult<
|
||||
|
||||
export type GuildScheduledEventManagerFetchSubscribersResult<T extends FetchGuildScheduledEventSubscribersOptions> =
|
||||
T extends { withMember: true }
|
||||
? Collection<Snowflake, GuildScheduledEventUser<true>>
|
||||
: Collection<Snowflake, GuildScheduledEventUser<false>>;
|
||||
? Collection<Snowflake, GuildScheduledEventUser<true>>
|
||||
: Collection<Snowflake, GuildScheduledEventUser<false>>;
|
||||
|
||||
export type GuildScheduledEventPrivacyLevel = keyof typeof GuildScheduledEventPrivacyLevels;
|
||||
|
||||
@ -6401,8 +6402,8 @@ export type ModalActionRowComponentResolvable =
|
||||
|
||||
export interface MessageActionRowOptions<
|
||||
T extends
|
||||
| MessageActionRowComponentResolvable
|
||||
| ModalActionRowComponentResolvable = MessageActionRowComponentResolvable,
|
||||
| MessageActionRowComponentResolvable
|
||||
| ModalActionRowComponentResolvable = MessageActionRowComponentResolvable,
|
||||
> extends BaseMessageComponentOptions {
|
||||
components: T[];
|
||||
}
|
||||
@ -6653,8 +6654,8 @@ export type MFALevel = keyof typeof MFALevels;
|
||||
|
||||
export interface ModalOptions {
|
||||
components:
|
||||
| MessageActionRow<ModalActionRowComponent>[]
|
||||
| MessageActionRowOptions<ModalActionRowComponentResolvable>[];
|
||||
| MessageActionRow<ModalActionRowComponent>[]
|
||||
| MessageActionRowOptions<ModalActionRowComponentResolvable>[];
|
||||
customId: string;
|
||||
title: string;
|
||||
}
|
||||
@ -6817,19 +6818,19 @@ export type Partialize<
|
||||
id: Snowflake;
|
||||
partial: true;
|
||||
} & {
|
||||
[K in keyof Omit<T, 'client' | 'id' | 'partial' | E>]: K extends N ? null : K extends M ? T[K] | null : T[K];
|
||||
};
|
||||
[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';
|
||||
|
||||
@ -7038,8 +7039,8 @@ export interface SweeperDefinitions {
|
||||
|
||||
export type SweeperOptions = {
|
||||
[K in keyof SweeperDefinitions]?: SweeperDefinitions[K][2] extends true
|
||||
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
|
||||
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
|
||||
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
|
||||
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
|
||||
};
|
||||
|
||||
export interface LimitedCollectionOptions<K, V> {
|
||||
@ -7178,12 +7179,12 @@ export interface WebhookClientDataURL {
|
||||
|
||||
export type FriendRequestOptions =
|
||||
| {
|
||||
user: UserResolvable;
|
||||
}
|
||||
user: UserResolvable;
|
||||
}
|
||||
| {
|
||||
username: string;
|
||||
discriminator: number | null;
|
||||
};
|
||||
username: string;
|
||||
discriminator: number | null;
|
||||
};
|
||||
|
||||
export type WebhookClientOptions = Pick<
|
||||
ClientOptions,
|
||||
|
Loading…
Reference in New Issue
Block a user