feat: acceptInvite options

This commit is contained in:
Elysia 2024-01-25 23:37:11 +07:00
parent 5758f0fdbf
commit 4e909fd889
2 changed files with 84 additions and 71 deletions

View File

@ -507,14 +507,22 @@ class Client extends BaseClient {
}); });
} }
/**
* Options for {@link Client#acceptInvite}.
* @typedef {Object} AcceptInviteOptions
* @property {boolean} [bypassOnboarding=true] Whether to bypass onboarding
* @property {boolean} [bypassVerify=true] Whether to bypass rule screening
*/
/** /**
* Join this Guild using this invite * Join this Guild using this invite
* @param {InviteResolvable} invite Invite code or URL * @param {InviteResolvable} invite Invite code or URL
* @param {AcceptInviteOptions} [options={ bypassOnboarding: true, bypassVerify: true }] Options
* @returns {Promise<Guild|DMChannel|GroupDMChannel>} * @returns {Promise<Guild|DMChannel|GroupDMChannel>}
* @example * @example
* await client.acceptInvite('https://discord.gg/genshinimpact') * await client.acceptInvite('https://discord.gg/genshinimpact', { bypassOnboarding: true, bypassVerify: true })
*/ */
async acceptInvite(invite) { async acceptInvite(invite, options = { bypassOnboarding: true, bypassVerify: true }) {
const code = DataResolver.resolveInviteCode(invite); const code = DataResolver.resolveInviteCode(invite);
if (!code) throw new Error('INVITE_RESOLVE_CODE'); if (!code) throw new Error('INVITE_RESOLVE_CODE');
const i = await this.fetchInvite(code); const i = await this.fetchInvite(code);
@ -539,7 +547,7 @@ class Client extends BaseClient {
if (i.guild?.id) { if (i.guild?.id) {
const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get(); const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get();
// Onboarding // Onboarding
if (onboardingData.enabled) { if (onboardingData.enabled && options.bypassOnboarding) {
const prompts = onboardingData.prompts.filter(o => o.in_onboarding); const prompts = onboardingData.prompts.filter(o => o.in_onboarding);
if (prompts.length) { if (prompts.length) {
const onboarding_prompts_seen = {}; const onboarding_prompts_seen = {};
@ -567,7 +575,7 @@ class Client extends BaseClient {
} }
} }
// Read rule // Read rule
if (data.show_verification_form) { if (data.show_verification_form && options.bypassVerify) {
// Check Guild // Check Guild
if (i.guild.verificationLevel == 'VERY_HIGH' && !this.user.phone) { if (i.guild.verificationLevel == 'VERY_HIGH' && !this.user.phone) {
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Cannot bypass verify (Phone required)`); this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Cannot bypass verify (Phone required)`);

139
typings/index.d.ts vendored
View File

@ -807,7 +807,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
/** @deprecated Use {@link Sweepers#sweepMessages} instead */ /** @deprecated Use {@link Sweepers#sweepMessages} instead */
public sweepMessages(lifetime?: number): number; public sweepMessages(lifetime?: number): number;
public toJSON(): unknown; public toJSON(): unknown;
public acceptInvite(invite: InviteResolvable): Promise<Guild | DMChannel | GroupDMChannel>; public acceptInvite(invite: InviteResolvable, options?: AcceptInviteOptions): Promise<Guild | DMChannel | GroupDMChannel>;
public redeemNitro(nitro: string, channel?: TextChannelResolvable, paymentSourceId?: Snowflake): Promise<any>; public redeemNitro(nitro: string, channel?: TextChannelResolvable, paymentSourceId?: Snowflake): Promise<any>;
public authorizeURL(url: string, options?: OAuth2AuthorizeOptions): Promise<any>; public authorizeURL(url: string, options?: OAuth2AuthorizeOptions): Promise<any>;
@ -836,6 +836,11 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof ClientEvents>): this; public removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof ClientEvents>): this;
} }
export interface AcceptInviteOptions {
bypassOnboarding: boolean;
bypassVerify: boolean;
}
export interface OAuth2AuthorizeOptions { export interface OAuth2AuthorizeOptions {
guild_id?: Snowflake; guild_id?: Snowflake;
permissions?: PermissionResolvable; permissions?: PermissionResolvable;
@ -1305,16 +1310,16 @@ export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
export class GuildAuditLogsEntry< export class GuildAuditLogsEntry<
TActionRaw extends GuildAuditLogsResolvable = 'ALL', TActionRaw extends GuildAuditLogsResolvable = 'ALL',
TAction = TActionRaw extends keyof GuildAuditLogsIds TAction = TActionRaw extends keyof GuildAuditLogsIds
? GuildAuditLogsIds[TActionRaw] ? GuildAuditLogsIds[TActionRaw]
: TActionRaw extends null : TActionRaw extends null
? 'ALL' ? 'ALL'
: TActionRaw, : TActionRaw,
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][1] ? GuildAuditLogsTypes[TAction][1]
: 'ALL', : 'ALL',
TTargetType extends GuildAuditLogsTarget = TAction extends keyof GuildAuditLogsTypes TTargetType extends GuildAuditLogsTarget = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][0] ? GuildAuditLogsTypes[TAction][0]
: 'UNKNOWN', : 'UNKNOWN',
> { > {
private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs); private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs);
public action: TAction; public action: TAction;
@ -1571,7 +1576,7 @@ export class HTTPError extends Error {
} }
// tslint:disable-next-line:no-empty-interface - Merge RateLimitData into RateLimitError to not have to type it again // 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 { export class RateLimitError extends Error {
private constructor(data: RateLimitData); private constructor(data: RateLimitData);
public name: 'RateLimitError'; public name: 'RateLimitError';
@ -1914,8 +1919,8 @@ export class MessageActionRow<
T extends MessageActionRowComponent | ModalActionRowComponent = MessageActionRowComponent, T extends MessageActionRowComponent | ModalActionRowComponent = MessageActionRowComponent,
U = T extends ModalActionRowComponent ? ModalActionRowComponentResolvable : MessageActionRowComponentResolvable, U = T extends ModalActionRowComponent ? ModalActionRowComponentResolvable : MessageActionRowComponentResolvable,
V = T extends ModalActionRowComponent V = T extends ModalActionRowComponent
? APIActionRowComponent<APIModalActionRowComponent> ? APIActionRowComponent<APIModalActionRowComponent>
: APIActionRowComponent<APIMessageActionRowComponent>, : APIActionRowComponent<APIMessageActionRowComponent>,
> extends BaseMessageComponent { > extends BaseMessageComponent {
// tslint:disable-next-line:ban-ts-ignore // tslint:disable-next-line:ban-ts-ignore
// @ts-ignore (TS:2344, Caused by TypeScript 4.8) // @ts-ignore (TS:2344, Caused by TypeScript 4.8)
@ -3699,13 +3704,13 @@ export class ApplicationCommandPermissionsManager<
public remove( public remove(
options: options:
| (FetchSingleOptions & { | (FetchSingleOptions & {
users: UserResolvable | UserResolvable[]; users: UserResolvable | UserResolvable[];
roles?: RoleResolvable | RoleResolvable[]; roles?: RoleResolvable | RoleResolvable[];
}) })
| (FetchSingleOptions & { | (FetchSingleOptions & {
users?: UserResolvable | UserResolvable[]; users?: UserResolvable | UserResolvable[];
roles: RoleResolvable | RoleResolvable[]; roles: RoleResolvable | RoleResolvable[];
}), }),
): Promise<ApplicationCommandPermissions[]>; ): Promise<ApplicationCommandPermissions[]>;
public set( public set(
options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] }, options: FetchSingleOptions & { permissions: ApplicationCommandPermissionData[] },
@ -4640,12 +4645,12 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
export interface ApplicationCommandAutocompleteOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> { export interface ApplicationCommandAutocompleteOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: type:
| 'STRING' | 'STRING'
| 'NUMBER' | 'NUMBER'
| 'INTEGER' | 'INTEGER'
| ApplicationCommandOptionTypes.STRING | ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.NUMBER | ApplicationCommandOptionTypes.NUMBER
| ApplicationCommandOptionTypes.INTEGER; | ApplicationCommandOptionTypes.INTEGER;
autocomplete: true; autocomplete: true;
} }
@ -4917,9 +4922,9 @@ export interface AutoModerationRuleCreateOptions {
reason?: string; 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 { export interface AutoModerationActionOptions {
type: AutoModerationActionType | AutoModerationActionTypes; type: AutoModerationActionType | AutoModerationActionTypes;
@ -5026,8 +5031,8 @@ export type CacheFactory = (
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>
? LimitedCollectionOptions<K, V> | number ? LimitedCollectionOptions<K, V> | number
: never; : never;
}; };
export interface CategoryCreateChannelOptions { export interface CategoryCreateChannelOptions {
permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>; permissionOverwrites?: OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>;
@ -5376,12 +5381,12 @@ export interface ConstantsClientApplicationAssetTypes {
export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & { export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & {
focused: true; focused: true;
type: type:
| 'STRING' | 'STRING'
| 'INTEGER' | 'INTEGER'
| 'NUMBER' | 'NUMBER'
| ApplicationCommandOptionTypes.STRING | ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.INTEGER | ApplicationCommandOptionTypes.INTEGER
| ApplicationCommandOptionTypes.NUMBER; | ApplicationCommandOptionTypes.NUMBER;
value: string; value: string;
}; };
@ -5936,20 +5941,20 @@ export interface GuildAuditLogsEntryExtraField {
MESSAGE_UNPIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake }; MESSAGE_UNPIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
MEMBER_DISCONNECT: { count: number }; MEMBER_DISCONNECT: { count: number };
CHANNEL_OVERWRITE_CREATE: CHANNEL_OVERWRITE_CREATE:
| Role | Role
| GuildMember | GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role } | { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member }; | { id: Snowflake; type: OverwriteTypes.member };
CHANNEL_OVERWRITE_UPDATE: CHANNEL_OVERWRITE_UPDATE:
| Role | Role
| GuildMember | GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role } | { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member }; | { id: Snowflake; type: OverwriteTypes.member };
CHANNEL_OVERWRITE_DELETE: CHANNEL_OVERWRITE_DELETE:
| Role | Role
| GuildMember | GuildMember
| { id: Snowflake; name: string; type: OverwriteTypes.role } | { id: Snowflake; name: string; type: OverwriteTypes.role }
| { id: Snowflake; type: OverwriteTypes.member }; | { id: Snowflake; type: OverwriteTypes.member };
STAGE_INSTANCE_CREATE: StageChannel | { id: Snowflake }; STAGE_INSTANCE_CREATE: StageChannel | { id: Snowflake };
STAGE_INSTANCE_DELETE: StageChannel | { id: Snowflake }; STAGE_INSTANCE_DELETE: StageChannel | { id: Snowflake };
STAGE_INSTANCE_UPDATE: StageChannel | { id: Snowflake }; STAGE_INSTANCE_UPDATE: StageChannel | { id: Snowflake };
@ -5980,8 +5985,8 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
INVITE: Invite; INVITE: Invite;
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User; MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
INTEGRATION: Integration; INTEGRATION: Integration;
CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown }; CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake;[x: string]: unknown };
THREAD: ThreadChannel | { id: Snowflake; [x: string]: unknown }; THREAD: ThreadChannel | { id: Snowflake;[x: string]: unknown };
STAGE_INSTANCE: StageInstance; STAGE_INSTANCE: StageInstance;
STICKER: Sticker; STICKER: Sticker;
GUILD_SCHEDULED_EVENT: GuildScheduledEvent; GUILD_SCHEDULED_EVENT: GuildScheduledEvent;
@ -6219,8 +6224,8 @@ export type GuildScheduledEventManagerFetchResult<
export type GuildScheduledEventManagerFetchSubscribersResult<T extends FetchGuildScheduledEventSubscribersOptions> = export type GuildScheduledEventManagerFetchSubscribersResult<T extends FetchGuildScheduledEventSubscribersOptions> =
T extends { withMember: true } T extends { withMember: true }
? Collection<Snowflake, GuildScheduledEventUser<true>> ? Collection<Snowflake, GuildScheduledEventUser<true>>
: Collection<Snowflake, GuildScheduledEventUser<false>>; : Collection<Snowflake, GuildScheduledEventUser<false>>;
export type GuildScheduledEventPrivacyLevel = keyof typeof GuildScheduledEventPrivacyLevels; export type GuildScheduledEventPrivacyLevel = keyof typeof GuildScheduledEventPrivacyLevels;
@ -6407,8 +6412,8 @@ export type ModalActionRowComponentResolvable =
export interface MessageActionRowOptions< export interface MessageActionRowOptions<
T extends T extends
| MessageActionRowComponentResolvable | MessageActionRowComponentResolvable
| ModalActionRowComponentResolvable = MessageActionRowComponentResolvable, | ModalActionRowComponentResolvable = MessageActionRowComponentResolvable,
> extends BaseMessageComponentOptions { > extends BaseMessageComponentOptions {
components: T[]; components: T[];
} }
@ -6659,8 +6664,8 @@ export type MFALevel = keyof typeof MFALevels;
export interface ModalOptions { export interface ModalOptions {
components: components:
| MessageActionRow<ModalActionRowComponent>[] | MessageActionRow<ModalActionRowComponent>[]
| MessageActionRowOptions<ModalActionRowComponentResolvable>[]; | MessageActionRowOptions<ModalActionRowComponentResolvable>[];
customId: string; customId: string;
title: string; title: string;
} }
@ -6821,19 +6826,19 @@ export type Partialize<
id: Snowflake; id: Snowflake;
partial: true; 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'> { export interface PartialDMChannel extends Partialize<DMChannel, null, null, 'lastMessageId'> {
lastMessageId: undefined; lastMessageId: undefined;
} }
export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> {} export interface PartialGuildMember extends Partialize<GuildMember, 'joinedAt' | 'joinedTimestamp'> { }
export interface PartialMessage 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 { export interface PartialOverwriteData {
id: Snowflake | number; id: Snowflake | number;
@ -6848,7 +6853,7 @@ export interface PartialRoleData extends RoleData {
export type PartialTypes = 'USER' | 'CHANNEL' | 'GUILD_MEMBER' | 'MESSAGE' | 'REACTION' | 'GUILD_SCHEDULED_EVENT'; 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'; export type PresenceStatusData = ClientPresenceStatus | 'invisible';
@ -7042,8 +7047,8 @@ export interface SweeperDefinitions {
export type SweeperOptions = { export type SweeperOptions = {
[K in keyof SweeperDefinitions]?: SweeperDefinitions[K][2] extends true [K in keyof SweeperDefinitions]?: SweeperDefinitions[K][2] extends true
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions ? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>; : SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
}; };
export interface LimitedCollectionOptions<K, V> { export interface LimitedCollectionOptions<K, V> {
@ -7182,12 +7187,12 @@ export interface WebhookClientDataURL {
export type FriendRequestOptions = export type FriendRequestOptions =
| { | {
user: UserResolvable; user: UserResolvable;
} }
| { | {
username: string; username: string;
discriminator: number | null; discriminator: number | null;
}; };
export type WebhookClientOptions = Pick< export type WebhookClientOptions = Pick<
ClientOptions, ClientOptions,