fix: temporary invite & feat: InviteFlags

This commit is contained in:
Elysia 2024-01-30 12:26:40 +07:00
parent 289f812ec6
commit 6307a4b7f2
6 changed files with 64 additions and 6 deletions

View File

@ -553,6 +553,11 @@ class Client extends BaseClient {
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Joined`);
// Guild
if (i.guild?.id) {
const guild = this.guilds.cache.get(i.guild?.id);
if (i.flags.has('GUEST')) {
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Guest invite`);
return guild;
}
if (options.bypassOnboarding) {
const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get();
// Onboarding
@ -607,7 +612,7 @@ class Client extends BaseClient {
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Bypassed verify`);
}
}
return this.guilds.cache.get(i.guild?.id);
return guild;
} else {
return this.channels.cache.has(i.channelId);
}

View File

@ -43,6 +43,7 @@ module.exports = (client, { d: data }, shard) => {
const guild = client.guilds.cache.get(gSetting.guild_id);
if (guild) guild.settings._patch(gSetting);
}
// Todo: data.auth_session_id_hash
if (largeGuilds.length) {
client.ws.broadcast({

View File

@ -47,17 +47,21 @@ class ClientUser extends User {
if ('purchased_flags' in data) {
/**
* Purchased state of the client user.
* @type {?PurchasedFlags}
* @type {Readonly<PurchasedFlags>}
*/
this.purchasedFlags = new PurchasedFlags(data.purchased_flags || 0);
this.purchasedFlags = new PurchasedFlags(data.purchased_flags || 0).freeze();
} else {
this.purchasedFlags = new PurchasedFlags().freeze();
}
if ('premium_usage_flags' in data) {
/**
* Premium usage state of the client user.
* @type {?PremiumUsageFlags}
* @type {Readonly<PremiumUsageFlags>}
*/
this.premiumUsageFlags = new PremiumUsageFlags(data.premium_usage_flags || 0);
} else {
this.premiumUsageFlags = new PremiumUsageFlags().freeze();
}
if ('phone' in data) {

View File

@ -6,6 +6,7 @@ const IntegrationApplication = require('./IntegrationApplication');
const InviteStageInstance = require('./InviteStageInstance');
const { Error } = require('../errors');
const { Endpoints } = require('../util/Constants');
const InviteFlags = require('../util/InviteFlags');
const Permissions = require('../util/Permissions');
// TODO: Convert `inviter` and `channel` in this class to a getter.
@ -242,6 +243,16 @@ class Invite extends Base {
} else {
this.guildScheduledEvent ??= null;
}
if ('flags' in data) {
/**
* The flags that are applied to the invite.
* @type {?Readonly<InviteFlags>}
*/
this.flags = new InviteFlags(data.flags).freeze();
} else {
this.flags ??= new InviteFlags().freeze();
}
}
/**

29
src/util/InviteFlags.js Normal file
View File

@ -0,0 +1,29 @@
'use strict';
const BitField = require('./BitField');
/**
* Data structure that makes it easy to interact with an {@link InviteFlags#flags} bitfield.
* @extends {BitField}
*/
class InviteFlags extends BitField {}
/**
* @name InviteFlags
* @kind constructor
* @memberof InviteFlags
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/
/**
* Numeric the Discord invite flags. All available properties:
* * `GUEST`
* * `VIEWED`
* @type {Object}
*/
InviteFlags.FLAGS = {
GUEST: 1 << 0,
VIEWED: 1 << 1,
};
module.exports = InviteFlags;

12
typings/index.d.ts vendored
View File

@ -334,6 +334,11 @@ export class PremiumUsageFlags extends BitField<PremiumUsageFlagsString> {
public static resolve(bit?: BitFieldResolvable<PremiumUsageFlagsString, number>): number;
}
export class InviteFlags extends BitField<InviteFlagsString> {
public static FLAGS: Record<InviteFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<InviteFlagsString, number>): number;
}
export abstract class AnonymousGuild extends BaseGuild {
protected constructor(client: Client, data: RawAnonymousGuildData, immediatePatch?: boolean);
public banner: string | null;
@ -873,8 +878,8 @@ export class ClientUser extends User {
public setPresence(data: PresenceData): ClientPresence;
public setStatus(status: PresenceStatusData, shardId?: number | number[]): ClientPresence;
public setUsername(username: string, password: string): Promise<this>;
public purchasedFlags: PurchasedFlags;
public premiumUsageFlags: PremiumUsageFlags;
public purchasedFlags: Readonly<PurchasedFlags>;
public premiumUsageFlags: Readonly<PremiumUsageFlags>;
public phone: string | null;
public nsfwAllowed?: boolean;
public email: string | null;
@ -1751,6 +1756,7 @@ export class Invite extends Base {
public static INVITES_PATTERN: RegExp;
public stageInstance: InviteStageInstance | null;
public guildScheduledEvent: GuildScheduledEvent | null;
public flags: Readonly<InviteFlags>;
}
export class InviteStageInstance extends Base {
@ -4365,6 +4371,8 @@ export type PurchasedFlagsString = 'NITRO_CLASSIC' | 'NITRO' | 'GUILD_BOOST' | '
export type PremiumUsageFlagsString = 'PREMIUM_DISCRIMINATOR' | 'ANIMATED_AVATAR' | 'PROFILE_BANNER';
export type InviteFlagsString = 'GUEST' | 'VIEWED';
export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;
export interface ActivityOptions {