fix: don't patch set data with undefined (#6694)

This commit is contained in:
Rodry
2021-10-03 13:59:52 +01:00
committed by GitHub
parent 8b4456e0aa
commit 9eb9591473
33 changed files with 1211 additions and 795 deletions

View File

@@ -15,36 +15,47 @@ class AnonymousGuild extends BaseGuild {
} }
_patch(data) { _patch(data) {
this.features = data.features; if ('features' in data) this.features = data.features;
if ('splash' in data) {
/** /**
* The hash of the guild invite splash image * The hash of the guild invite splash image
* @type {?string} * @type {?string}
*/ */
this.splash = data.splash; this.splash = data.splash;
}
if ('banner' in data) {
/** /**
* The hash of the guild banner * The hash of the guild banner
* @type {?string} * @type {?string}
*/ */
this.banner = data.banner; this.banner = data.banner;
}
if ('description' in data) {
/** /**
* The description of the guild, if any * The description of the guild, if any
* @type {?string} * @type {?string}
*/ */
this.description = data.description; this.description = data.description;
}
if ('verification_level' in data) {
/** /**
* The verification level of the guild * The verification level of the guild
* @type {VerificationLevel} * @type {VerificationLevel}
*/ */
this.verificationLevel = VerificationLevels[data.verification_level]; this.verificationLevel = VerificationLevels[data.verification_level];
}
if ('vanity_url_code' in data) {
/** /**
* The vanity invite code of the guild, if any * The vanity invite code of the guild, if any
* @type {?string} * @type {?string}
*/ */
this.vanityURLCode = data.vanity_url_code; this.vanityURLCode = data.vanity_url_code;
}
if ('nsfw_level' in data) { if ('nsfw_level' in data) {
/** /**

View File

@@ -54,36 +54,48 @@ class ApplicationCommand extends Base {
} }
_patch(data) { _patch(data) {
if ('name' in data) {
/** /**
* The name of this command * The name of this command
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('description' in data) {
/** /**
* The description of this command * The description of this command
* @type {string} * @type {string}
*/ */
this.description = data.description; this.description = data.description;
}
if ('options' in data) {
/** /**
* The options of this command * The options of this command
* @type {ApplicationCommandOption[]} * @type {ApplicationCommandOption[]}
*/ */
this.options = data.options?.map(o => this.constructor.transformOption(o, true)) ?? []; this.options = data.options.map(o => this.constructor.transformOption(o, true));
} else {
this.options ??= [];
}
if ('default_permission' in data) {
/** /**
* Whether the command is enabled by default when the app is added to a guild * Whether the command is enabled by default when the app is added to a guild
* @type {boolean} * @type {boolean}
*/ */
this.defaultPermission = data.default_permission; this.defaultPermission = data.default_permission;
}
if ('version' in data) {
/** /**
* Autoincrementing version identifier updated during substantial record changes * Autoincrementing version identifier updated during substantial record changes
* @type {Snowflake} * @type {Snowflake}
*/ */
this.version = data.version; this.version = data.version;
} }
}
/** /**
* The timestamp the command was created at * The timestamp the command was created at

View File

@@ -25,9 +25,9 @@ class BaseGuildEmoji extends Emoji {
} }
_patch(data) { _patch(data) {
if (data.name) this.name = data.name; if ('name' in data) this.name = data.name;
if (typeof data.require_colons !== 'undefined') { if ('require_colons' in data) {
/** /**
* Whether or not this emoji requires colons surrounding it * Whether or not this emoji requires colons surrounding it
* @type {?boolean} * @type {?boolean}
@@ -35,7 +35,7 @@ class BaseGuildEmoji extends Emoji {
this.requiresColons = data.require_colons; this.requiresColons = data.require_colons;
} }
if (typeof data.managed !== 'undefined') { if ('managed' in data) {
/** /**
* Whether this emoji is managed by an external service * Whether this emoji is managed by an external service
* @type {?boolean} * @type {?boolean}
@@ -43,7 +43,7 @@ class BaseGuildEmoji extends Emoji {
this.managed = data.managed; this.managed = data.managed;
} }
if (typeof data.available !== 'undefined') { if ('available' in data) {
/** /**
* Whether this emoji is available * Whether this emoji is available
* @type {?boolean} * @type {?boolean}

View File

@@ -12,24 +12,30 @@ class BaseGuildVoiceChannel extends GuildChannel {
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
if ('rtc_region' in data) {
/** /**
* The RTC region for this voice-based channel. This region is automatically selected if `null`. * The RTC region for this voice-based channel. This region is automatically selected if `null`.
* @type {?string} * @type {?string}
*/ */
this.rtcRegion = data.rtc_region; this.rtcRegion = data.rtc_region;
}
if ('bitrate' in data) {
/** /**
* The bitrate of this voice-based channel * The bitrate of this voice-based channel
* @type {number} * @type {number}
*/ */
this.bitrate = data.bitrate; this.bitrate = data.bitrate;
}
if ('user_limit' in data) {
/** /**
* The maximum amount of users allowed in this channel. * The maximum amount of users allowed in this channel.
* @type {number} * @type {number}
*/ */
this.userLimit = data.user_limit; this.userLimit = data.user_limit;
} }
}
/** /**
* The members in this voice-based channel * The members in this voice-based channel

View File

@@ -23,35 +23,53 @@ class ClientApplication extends Application {
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
if ('flags' in data) {
/** /**
* The flags this application has * The flags this application has
* @type {ApplicationFlags} * @type {ApplicationFlags}
*/ */
this.flags = 'flags' in data ? new ApplicationFlags(data.flags).freeze() : this.flags; this.flags = new ApplicationFlags(data.flags).freeze();
}
if ('cover_image' in data) {
/** /**
* The hash of the application's cover image * The hash of the application's cover image
* @type {?string} * @type {?string}
*/ */
this.cover = data.cover_image ?? this.cover ?? null; this.cover = data.cover_image;
} else {
this.cover ??= null;
}
if ('rpc_origins' in data) {
/** /**
* The application's RPC origins, if enabled * The application's RPC origins, if enabled
* @type {string[]} * @type {string[]}
*/ */
this.rpcOrigins = data.rpc_origins ?? this.rpcOrigins ?? []; this.rpcOrigins = data.rpc_origins;
} else {
this.rpcOrigins ??= [];
}
if ('bot_require_code_grant' in data) {
/** /**
* If this application's bot requires a code grant when using the OAuth2 flow * If this application's bot requires a code grant when using the OAuth2 flow
* @type {?boolean} * @type {?boolean}
*/ */
this.botRequireCodeGrant = data.bot_require_code_grant ?? this.botRequireCodeGrant ?? null; this.botRequireCodeGrant = data.bot_require_code_grant;
} else {
this.botRequireCodeGrant ??= null;
}
if ('bot_public' in data) {
/** /**
* If this application's bot is public * If this application's bot is public
* @type {?boolean} * @type {?boolean}
*/ */
this.botPublic = data.bot_public ?? this.botPublic ?? null; this.botPublic = data.bot_public;
} else {
this.botPublic ??= null;
}
/** /**
* The owner of this OAuth application * The owner of this OAuth application

View File

@@ -29,7 +29,7 @@ class ClientUser extends User {
this.mfaEnabled ??= null; this.mfaEnabled ??= null;
} }
if (data.token) this.client.token = data.token; if ('token' in data) this.client.token = data.token;
} }
/** /**

View File

@@ -38,17 +38,23 @@ class DMChannel extends Channel {
this.recipient = this.client.users._add(data.recipients[0]); this.recipient = this.client.users._add(data.recipients[0]);
} }
if ('last_message_id' in data) {
/** /**
* The channel's last message id, if one was sent * The channel's last message id, if one was sent
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.lastMessageId = data.last_message_id; this.lastMessageId = data.last_message_id;
}
if ('last_pin_timestamp' in data) {
/** /**
* The timestamp when the last pinned message was pinned, if there was one * The timestamp when the last pinned message was pinned, if there was one
* @type {?number} * @type {?number}
*/ */
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null; this.lastPinTimestamp = new Date(data.last_pin_timestamp).getTime();
} else {
this.lastPinTimestamp ??= null;
}
} }
/** /**

View File

@@ -140,27 +140,33 @@ class Guild extends AnonymousGuild {
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
this.id = data.id; this.id = data.id;
this.name = data.name; if ('name' in data) this.name = data.name;
this.icon = data.icon; if ('icon' in data) this.icon = data.icon;
this.available = !data.unavailable; if ('unavailable' in data) this.available = !data.unavailable;
if ('discovery_splash' in data) {
/** /**
* The hash of the guild discovery splash image * The hash of the guild discovery splash image
* @type {?string} * @type {?string}
*/ */
this.discoverySplash = data.discovery_splash; this.discoverySplash = data.discovery_splash;
}
if ('member_count' in data) {
/** /**
* The full amount of members in this guild * The full amount of members in this guild
* @type {number} * @type {number}
*/ */
this.memberCount = data.member_count ?? this.memberCount; this.memberCount = data.member_count;
}
if ('large' in data) {
/** /**
* Whether the guild is "large" (has more than large_threshold members, 50 by default) * Whether the guild is "large" (has more than {@link WebsocketOptions large_threshold} members, 50 by default)
* @type {boolean} * @type {boolean}
*/ */
this.large = Boolean(data.large ?? this.large); this.large = Boolean(data.large);
}
/** /**
* An array of enabled guild features, here are the possible values: * An array of enabled guild features, here are the possible values:
@@ -189,37 +195,47 @@ class Guild extends AnonymousGuild {
* @see {@link https://discord.com/developers/docs/resources/guild#guild-object-guild-features} * @see {@link https://discord.com/developers/docs/resources/guild#guild-object-guild-features}
*/ */
if ('application_id' in data) {
/** /**
* The id of the application that created this guild (if applicable) * The id of the application that created this guild (if applicable)
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.applicationId = data.application_id; this.applicationId = data.application_id;
}
if ('afk_timeout' in data) {
/** /**
* The time in seconds before a user is counted as "away from keyboard" * The time in seconds before a user is counted as "away from keyboard"
* @type {?number} * @type {?number}
*/ */
this.afkTimeout = data.afk_timeout; this.afkTimeout = data.afk_timeout;
}
if ('afk_channel_id' in data) {
/** /**
* The id of the voice channel where AFK members are moved * The id of the voice channel where AFK members are moved
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.afkChannelId = data.afk_channel_id; this.afkChannelId = data.afk_channel_id;
}
if ('system_channel_id' in data) {
/** /**
* The system channel's id * The system channel's id
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.systemChannelId = data.system_channel_id; this.systemChannelId = data.system_channel_id;
}
if ('premium_tier' in data) {
/** /**
* The premium tier of this guild * The premium tier of this guild
* @type {PremiumTier} * @type {PremiumTier}
*/ */
this.premiumTier = PremiumTiers[data.premium_tier]; this.premiumTier = PremiumTiers[data.premium_tier];
}
if (typeof data.premium_subscription_count !== 'undefined') { if ('premium_subscription_count' in data) {
/** /**
* The total number of boosts for this server * The total number of boosts for this server
* @type {?number} * @type {?number}
@@ -227,7 +243,7 @@ class Guild extends AnonymousGuild {
this.premiumSubscriptionCount = data.premium_subscription_count; this.premiumSubscriptionCount = data.premium_subscription_count;
} }
if (typeof data.widget_enabled !== 'undefined') { if ('widget_enabled' in data) {
/** /**
* Whether widget images are enabled on this guild * Whether widget images are enabled on this guild
* @type {?boolean} * @type {?boolean}
@@ -235,7 +251,7 @@ class Guild extends AnonymousGuild {
this.widgetEnabled = data.widget_enabled; this.widgetEnabled = data.widget_enabled;
} }
if (typeof data.widget_channel_id !== 'undefined') { if ('widget_channel_id' in data) {
/** /**
* The widget channel's id, if enabled * The widget channel's id, if enabled
* @type {?string} * @type {?string}
@@ -243,37 +259,47 @@ class Guild extends AnonymousGuild {
this.widgetChannelId = data.widget_channel_id; this.widgetChannelId = data.widget_channel_id;
} }
if ('explicit_content_filter' in data) {
/** /**
* The explicit content filter level of the guild * The explicit content filter level of the guild
* @type {ExplicitContentFilterLevel} * @type {ExplicitContentFilterLevel}
*/ */
this.explicitContentFilter = ExplicitContentFilterLevels[data.explicit_content_filter]; this.explicitContentFilter = ExplicitContentFilterLevels[data.explicit_content_filter];
}
if ('mfa_level' in data) {
/** /**
* The required MFA level for this guild * The required MFA level for this guild
* @type {MFALevel} * @type {MFALevel}
*/ */
this.mfaLevel = MFALevels[data.mfa_level]; this.mfaLevel = MFALevels[data.mfa_level];
}
if ('joined_at' in data) {
/** /**
* The timestamp the client user joined the guild at * The timestamp the client user joined the guild at
* @type {number} * @type {number}
*/ */
this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp; this.joinedTimestamp = new Date(data.joined_at).getTime();
}
if ('default_message_notifications' in data) {
/** /**
* The default message notification level of the guild * The default message notification level of the guild
* @type {DefaultMessageNotificationLevel} * @type {DefaultMessageNotificationLevel}
*/ */
this.defaultMessageNotifications = DefaultMessageNotificationLevels[data.default_message_notifications]; this.defaultMessageNotifications = DefaultMessageNotificationLevels[data.default_message_notifications];
}
if ('system_channel_flags' in data) {
/** /**
* The value set for the guild's system channel flags * The value set for the guild's system channel flags
* @type {Readonly<SystemChannelFlags>} * @type {Readonly<SystemChannelFlags>}
*/ */
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze(); this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
}
if (typeof data.max_members !== 'undefined') { if ('max_members' in data) {
/** /**
* The maximum amount of members the guild can have * The maximum amount of members the guild can have
* @type {?number} * @type {?number}
@@ -283,7 +309,7 @@ class Guild extends AnonymousGuild {
this.maximumMembers ??= null; this.maximumMembers ??= null;
} }
if (typeof data.max_presences !== 'undefined') { if ('max_presences' in data) {
/** /**
* The maximum amount of presences the guild can have * The maximum amount of presences the guild can have
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
@@ -294,7 +320,7 @@ class Guild extends AnonymousGuild {
this.maximumPresences ??= null; this.maximumPresences ??= null;
} }
if (typeof data.approximate_member_count !== 'undefined') { if ('approximate_member_count' in data) {
/** /**
* The approximate amount of members the guild has * The approximate amount of members the guild has
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
@@ -305,7 +331,7 @@ class Guild extends AnonymousGuild {
this.approximateMemberCount ??= null; this.approximateMemberCount ??= null;
} }
if (typeof data.approximate_presence_count !== 'undefined') { if ('approximate_presence_count' in data) {
/** /**
* The approximate amount of presences the guild has * The approximate amount of presences the guild has
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info> * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
@@ -321,26 +347,32 @@ class Guild extends AnonymousGuild {
* <info>You will need to fetch this parameter using {@link Guild#fetchVanityData} if you want to receive it</info> * <info>You will need to fetch this parameter using {@link Guild#fetchVanityData} if you want to receive it</info>
* @type {?number} * @type {?number}
*/ */
this.vanityURLUses = null; this.vanityURLUses ??= null;
if ('rules_channel_id' in data) {
/** /**
* The rules channel's id for the guild * The rules channel's id for the guild
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.rulesChannelId = data.rules_channel_id; this.rulesChannelId = data.rules_channel_id;
}
if ('public_updates_channel_id' in data) {
/** /**
* The community updates channel's id for the guild * The community updates channel's id for the guild
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.publicUpdatesChannelId = data.public_updates_channel_id; this.publicUpdatesChannelId = data.public_updates_channel_id;
}
if ('preferred_locale' in data) {
/** /**
* The preferred locale of the guild, defaults to `en-US` * The preferred locale of the guild, defaults to `en-US`
* @type {string} * @type {string}
* @see {@link https://discord.com/developers/docs/dispatch/field-values#predefined-field-values-accepted-locales} * @see {@link https://discord.com/developers/docs/dispatch/field-values#predefined-field-values-accepted-locales}
*/ */
this.preferredLocale = data.preferred_locale; this.preferredLocale = data.preferred_locale;
}
if (data.channels) { if (data.channels) {
this.channels.cache.clear(); this.channels.cache.clear();
@@ -365,7 +397,7 @@ class Guild extends AnonymousGuild {
for (const guildUser of data.members) this.members._add(guildUser); for (const guildUser of data.members) this.members._add(guildUser);
} }
if (data.owner_id) { if ('owner_id' in data) {
/** /**
* The user id of this guild's owner * The user id of this guild's owner
* @type {Snowflake} * @type {Snowflake}

View File

@@ -25,11 +25,13 @@ class GuildBan extends Base {
} }
_patch(data) { _patch(data) {
if ('user' in data) {
/** /**
* The user this ban applies to * The user this ban applies to
* @type {User} * @type {User}
*/ */
this.user = this.client.users._add(data.user, true); this.user = this.client.users._add(data.user, true);
}
if ('reason' in data) { if ('reason' in data) {
/** /**

View File

@@ -30,53 +30,71 @@ class GuildPreview extends Base {
*/ */
this.id = data.id; this.id = data.id;
if ('name' in data) {
/** /**
* The name of this guild * The name of this guild
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('icon' in data) {
/** /**
* The icon of this guild * The icon of this guild
* @type {?string} * @type {?string}
*/ */
this.icon = data.icon; this.icon = data.icon;
}
if ('splash' in data) {
/** /**
* The splash icon of this guild * The splash icon of this guild
* @type {?string} * @type {?string}
*/ */
this.splash = data.splash; this.splash = data.splash;
}
if ('discovery_splash' in data) {
/** /**
* The discovery splash icon of this guild * The discovery splash icon of this guild
* @type {?string} * @type {?string}
*/ */
this.discoverySplash = data.discovery_splash; this.discoverySplash = data.discovery_splash;
}
if ('features' in data) {
/** /**
* An array of enabled guild features * An array of enabled guild features
* @type {Features[]} * @type {Features[]}
*/ */
this.features = data.features; this.features = data.features;
}
if ('approximate_member_count' in data) {
/** /**
* The approximate count of members in this guild * The approximate count of members in this guild
* @type {number} * @type {number}
*/ */
this.approximateMemberCount = data.approximate_member_count; this.approximateMemberCount = data.approximate_member_count;
}
if ('approximate_presence_count' in data) {
/** /**
* The approximate count of online members in this guild * The approximate count of online members in this guild
* @type {number} * @type {number}
*/ */
this.approximatePresenceCount = data.approximate_presence_count; this.approximatePresenceCount = data.approximate_presence_count;
}
if ('description' in data) {
/** /**
* The description for this guild * The description for this guild
* @type {?string} * @type {?string}
*/ */
this.description = data.description ?? null; this.description = data.description;
} else {
this.description ??= null;
}
if (!this.emojis) { if (!this.emojis) {
/** /**

View File

@@ -25,65 +25,85 @@ class GuildTemplate extends Base {
* @private * @private
*/ */
_patch(data) { _patch(data) {
if ('code' in data) {
/** /**
* The unique code of this template * The unique code of this template
* @type {string} * @type {string}
*/ */
this.code = data.code; this.code = data.code;
}
if ('name' in data) {
/** /**
* The name of this template * The name of this template
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('description' in data) {
/** /**
* The description of this template * The description of this template
* @type {?string} * @type {?string}
*/ */
this.description = data.description; this.description = data.description;
}
if ('usage_count' in data) {
/** /**
* The amount of times this template has been used * The amount of times this template has been used
* @type {number} * @type {number}
*/ */
this.usageCount = data.usage_count; this.usageCount = data.usage_count;
}
if ('creator_id' in data) {
/** /**
* The id of the user that created this template * The id of the user that created this template
* @type {Snowflake} * @type {Snowflake}
*/ */
this.creatorId = data.creator_id; this.creatorId = data.creator_id;
}
if ('creator' in data) {
/** /**
* The user that created this template * The user that created this template
* @type {User} * @type {User}
*/ */
this.creator = this.client.users._add(data.creator); this.creator = this.client.users._add(data.creator);
}
if ('created_at' in data) {
/** /**
* The time of when this template was created at * The time of when this template was created at
* @type {Date} * @type {Date}
*/ */
this.createdAt = new Date(data.created_at); this.createdAt = new Date(data.created_at);
}
if ('updated_at' in data) {
/** /**
* The time of when this template was last synced to the guild * The time of when this template was last synced to the guild
* @type {Date} * @type {Date}
*/ */
this.updatedAt = new Date(data.updated_at); this.updatedAt = new Date(data.updated_at);
}
if ('source_guild_id' in data) {
/** /**
* The id of the guild that this template belongs to * The id of the guild that this template belongs to
* @type {Snowflake} * @type {Snowflake}
*/ */
this.guildId = data.source_guild_id; this.guildId = data.source_guild_id;
}
if ('serialized_source_guild' in data) {
/** /**
* The data of the guild that this template would create * The data of the guild that this template would create
* @type {APIGuild} * @type {APIGuild}
*/ */
this.serializedGuild = data.serialized_source_guild; this.serializedGuild = data.serialized_source_guild;
}
/** /**
* Whether this template has unsynced changes * Whether this template has unsynced changes

View File

@@ -125,17 +125,21 @@ class Integration extends Base {
} }
_patch(data) { _patch(data) {
if ('expire_behavior' in data) {
/** /**
* The behavior of expiring subscribers * The behavior of expiring subscribers
* @type {?number} * @type {?number}
*/ */
this.expireBehavior = data.expire_behavior; this.expireBehavior = data.expire_behavior;
}
if ('expire_grace_period' in data) {
/** /**
* The grace period before expiring subscribers * The grace period before expiring subscribers
* @type {?number} * @type {?number}
*/ */
this.expireGracePeriod = data.expire_grace_period; this.expireGracePeriod = data.expire_grace_period;
}
if ('application' in data) { if ('application' in data) {
if (this.application) { if (this.application) {

View File

@@ -10,53 +10,85 @@ class IntegrationApplication extends Application {
_patch(data) { _patch(data) {
super._patch(data); super._patch(data);
if ('bot' in data) {
/** /**
* The bot user for this application * The bot user for this application
* @type {?User} * @type {?User}
*/ */
this.bot = data.bot ? this.client.users._add(data.bot) : this.bot ?? null; this.bot = this.client.users._add(data.bot);
} else {
this.bot ??= null;
}
if ('terms_of_service_url' in data) {
/** /**
* The url of the application's terms of service * The url of the application's terms of service
* @type {?string} * @type {?string}
*/ */
this.termsOfServiceURL = data.terms_of_service_url ?? this.termsOfServiceURL ?? null; this.termsOfServiceURL = data.terms_of_service_url;
} else {
this.termsOfServiceURL ??= null;
}
if ('privacy_policy_url' in data) {
/** /**
* The url of the application's privacy policy * The url of the application's privacy policy
* @type {?string} * @type {?string}
*/ */
this.privacyPolicyURL = data.privacy_policy_url ?? this.privacyPolicyURL ?? null; this.privacyPolicyURL = data.privacy_policy_url;
} else {
this.privacyPolicyURL ??= null;
}
if ('rpc_origins' in data) {
/** /**
* The Array of RPC origin urls * The Array of RPC origin urls
* @type {string[]} * @type {string[]}
*/ */
this.rpcOrigins = data.rpc_origins ?? this.rpcOrigins ?? []; this.rpcOrigins = data.rpc_origins;
} else {
this.rpcOrigins ??= [];
}
if ('summary' in data) {
/** /**
* The application's summary * The application's summary
* @type {?string} * @type {?string}
*/ */
this.summary = data.summary ?? this.summary ?? null; this.summary = data.summary;
} else {
this.summary ??= null;
}
if ('hook' in data) {
/** /**
* Whether the application can be default hooked by the client * Whether the application can be default hooked by the client
* @type {?boolean} * @type {?boolean}
*/ */
this.hook = data.hook ?? this.hook ?? null; this.hook = data.hook;
} else {
this.hook ??= null;
}
if ('cover_image' in data) {
/** /**
* The hash of the application's cover image * The hash of the application's cover image
* @type {?string} * @type {?string}
*/ */
this.cover = data.cover_image ?? this.cover ?? null; this.cover = data.cover_image;
} else {
this.cover ??= null;
}
if ('verify_key' in data) {
/** /**
* The hex-encoded key for verification in interactions and the GameSDK's GetTicket * The hex-encoded key for verification in interactions and the GameSDK's GetTicket
* @type {?string} * @type {?string}
*/ */
this.verifyKey = data.verify_key ?? this.verifyKey ?? null; this.verifyKey = data.verify_key;
} else {
this.verifyKey ??= null;
}
} }
} }

View File

@@ -24,72 +24,108 @@ class Invite extends Base {
* The guild the invite is for including welcome screen data if present * The guild the invite is for including welcome screen data if present
* @type {?(Guild|InviteGuild)} * @type {?(Guild|InviteGuild)}
*/ */
this.guild = null; this.guild ??= null;
if (data.guild) { if (data.guild) {
this.guild = this.client.guilds.resolve(data.guild.id) ?? new InviteGuild(this.client, data.guild); this.guild = this.client.guilds.resolve(data.guild.id) ?? new InviteGuild(this.client, data.guild);
} }
if ('code' in data) {
/** /**
* The code for this invite * The code for this invite
* @type {string} * @type {string}
*/ */
this.code = data.code; this.code = data.code;
}
if ('approximate_presence_count' in data) {
/** /**
* The approximate number of online members of the guild this invite is for * The approximate number of online members of the guild this invite is for
* @type {?number} * @type {?number}
*/ */
this.presenceCount = data.approximate_presence_count ?? null; this.presenceCount = data.approximate_presence_count;
} else {
this.presenceCount ??= null;
}
if ('approximate_member_count' in data) {
/** /**
* The approximate total number of members of the guild this invite is for * The approximate total number of members of the guild this invite is for
* @type {?number} * @type {?number}
*/ */
this.memberCount = data.approximate_member_count ?? null; this.memberCount = data.approximate_member_count;
} else {
this.memberCount ??= null;
}
if ('temporary' in data) {
/** /**
* Whether or not this invite is temporary * Whether or not this invite only grants temporary membership
* @type {?boolean} * @type {?boolean}
*/ */
this.temporary = data.temporary ?? null; this.temporary = data.temporary ?? null;
} else {
this.temporary ??= null;
}
if ('max_age' in data) {
/** /**
* The maximum age of the invite, in seconds, 0 if never expires * The maximum age of the invite, in seconds, 0 if never expires
* @type {?number} * @type {?number}
*/ */
this.maxAge = data.max_age ?? null; this.maxAge = data.max_age;
} else {
this.maxAge ??= null;
}
if ('uses' in data) {
/** /**
* How many times this invite has been used * How many times this invite has been used
* @type {?number} * @type {?number}
*/ */
this.uses = data.uses ?? null; this.uses = data.uses;
} else {
this.uses ??= null;
}
if ('max_uses' in data) {
/** /**
* The maximum uses of this invite * The maximum uses of this invite
* @type {?number} * @type {?number}
*/ */
this.maxUses = data.max_uses ?? null; this.maxUses = data.max_uses;
} else {
this.maxUses ??= null;
}
if ('inviter' in data) {
/** /**
* The user who created this invite * The user who created this invite
* @type {?User} * @type {?User}
*/ */
this.inviter = data.inviter ? this.client.users._add(data.inviter) : null; this.inviter = this.client.users._add(data.inviter);
} else {
this.inviter ??= null;
}
if ('target_user' in data) {
/** /**
* The user whose stream to display for this voice channel stream invite * The user whose stream to display for this voice channel stream invite
* @type {?User} * @type {?User}
*/ */
this.targetUser = data.target_user ? this.client.users._add(data.target_user) : null; this.targetUser = this.client.users._add(data.target_user);
} else {
this.targetUser ??= null;
}
if ('target_application' in data) {
/** /**
* The embedded application to open for this voice channel embedded application invite * The embedded application to open for this voice channel embedded application invite
* @type {?IntegrationApplication} * @type {?IntegrationApplication}
*/ */
this.targetApplication = data.target_application this.targetApplication = new IntegrationApplication(this.client, data.target_application);
? new IntegrationApplication(this.client, data.target_application) } else {
: null; this.targetApplication ??= null;
}
/** /**
* The type of the invite target: * The type of the invite target:
@@ -99,34 +135,46 @@ class Invite extends Base {
* @see {@link https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types} * @see {@link https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types}
*/ */
if ('target_type' in data) {
/** /**
* The target type * The target type
* @type {?TargetType} * @type {?TargetType}
*/ */
this.targetType = data.target_type ?? null; this.targetType = data.target_type;
} else {
this.targetType ??= null;
}
if ('channel' in data) {
/** /**
* The channel the invite is for * The channel the invite is for
* @type {Channel} * @type {Channel}
*/ */
this.channel = this.client.channels._add(data.channel, this.guild, { cache: false }); this.channel = this.client.channels._add(data.channel, this.guild, { cache: false });
}
if ('created_at' in data) {
/** /**
* The timestamp the invite was created at * The timestamp the invite was created at
* @type {?number} * @type {?number}
*/ */
this.createdTimestamp = 'created_at' in data ? new Date(data.created_at).getTime() : null; this.createdTimestamp = new Date(data.created_at).getTime();
} else {
this.createdTimestamp ??= null;
}
this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; if ('expires_at' in data) this._expiresTimestamp = new Date(data.expires_at).getTime();
else this._expiresTimestamp ??= null;
if ('stage_instance' in data) {
/** /**
* The stage instance data if there is a public {@link StageInstance} in the stage channel this invite is for * The stage instance data if there is a public {@link StageInstance} in the stage channel this invite is for
* @type {?InviteStageInstance} * @type {?InviteStageInstance}
*/ */
this.stageInstance = this.stageInstance = new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id);
'stage_instance' in data } else {
? new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id) this.stageInstance ??= null;
: null; }
} }
/** /**

View File

@@ -33,23 +33,29 @@ class InviteStageInstance extends Base {
} }
_patch(data) { _patch(data) {
if ('topic' in data) {
/** /**
* The topic of the stage instance * The topic of the stage instance
* @type {string} * @type {string}
*/ */
this.topic = data.topic; this.topic = data.topic;
}
if ('participant_count' in data) {
/** /**
* The number of users in the stage channel * The number of users in the stage channel
* @type {number} * @type {number}
*/ */
this.participantCount = data.participant_count; this.participantCount = data.participant_count;
}
if ('speaker_count' in data) {
/** /**
* The number of users speaking in the stage channel * The number of users speaking in the stage channel
* @type {number} * @type {number}
*/ */
this.speakerCount = data.speaker_count; this.speakerCount = data.speaker_count;
}
this.members.clear(); this.members.clear();
for (const rawMember of data.members) { for (const rawMember of data.members) {

View File

@@ -71,9 +71,9 @@ class Message extends Base {
* @type {?boolean} * @type {?boolean}
*/ */
this.system = SystemMessageTypes.includes(this.type); this.system = SystemMessageTypes.includes(this.type);
} else if (typeof this.type !== 'string') { } else {
this.system = null; this.system ??= null;
this.type = null; this.type ??= null;
} }
if ('content' in data) { if ('content' in data) {

View File

@@ -68,41 +68,59 @@ class MessageAttachment {
*/ */
this.id = data.id; this.id = data.id;
if ('size' in data) {
/** /**
* The size of this attachment in bytes * The size of this attachment in bytes
* @type {number} * @type {number}
*/ */
this.size = data.size; this.size = data.size;
}
if ('url' in data) {
/** /**
* The URL to this attachment * The URL to this attachment
* @type {string} * @type {string}
*/ */
this.url = data.url; this.url = data.url;
}
if ('proxy_url' in data) {
/** /**
* The Proxy URL to this attachment * The Proxy URL to this attachment
* @type {string} * @type {string}
*/ */
this.proxyURL = data.proxy_url; this.proxyURL = data.proxy_url;
}
if ('height' in data) {
/** /**
* The height of this attachment (if an image or video) * The height of this attachment (if an image or video)
* @type {?number} * @type {?number}
*/ */
this.height = data.height ?? null; this.height = data.height;
} else {
this.height ??= null;
}
if ('width' in data) {
/** /**
* The width of this attachment (if an image or video) * The width of this attachment (if an image or video)
* @type {?number} * @type {?number}
*/ */
this.width = data.width ?? null; this.width = data.width;
} else {
this.width ??= null;
}
if ('content_type' in data) {
/** /**
* This media type of this attachment * This media type of this attachment
* @type {?string} * @type {?string}
*/ */
this.contentType = data.content_type ?? null; this.contentType = data.content_type;
} else {
this.contentType ??= null;
}
/** /**
* Whether this attachment is ephemeral * Whether this attachment is ephemeral

View File

@@ -47,13 +47,12 @@ class MessageReaction {
} }
_patch(data) { _patch(data) {
// eslint-disable-next-line eqeqeq if ('count' in data) {
if (this.count == undefined) {
/** /**
* The number of people that have given the same reaction * The number of people that have given the same reaction
* @type {?number} * @type {?number}
*/ */
this.count = data.count; this.count ??= data.count;
} }
} }

View File

@@ -32,24 +32,30 @@ class PermissionOverwrites extends Base {
*/ */
this.id = data.id; this.id = data.id;
if ('type' in data) {
/** /**
* The type of this overwrite * The type of this overwrite
* @type {OverwriteType} * @type {OverwriteType}
*/ */
this.type = typeof data.type === 'number' ? OverwriteTypes[data.type] : data.type; this.type = typeof data.type === 'number' ? OverwriteTypes[data.type] : data.type;
}
if ('deny' in data) {
/** /**
* The permissions that are denied for the user or role. * The permissions that are denied for the user or role.
* @type {Readonly<Permissions>} * @type {Readonly<Permissions>}
*/ */
this.deny = new Permissions(BigInt(data.deny)).freeze(); this.deny = new Permissions(BigInt(data.deny)).freeze();
}
if ('allow' in data) {
/** /**
* The permissions that are allowed for the user or role. * The permissions that are allowed for the user or role.
* @type {Readonly<Permissions>} * @type {Readonly<Permissions>}
*/ */
this.allow = new Permissions(BigInt(data.allow)).freeze(); this.allow = new Permissions(BigInt(data.allow)).freeze();
} }
}
/** /**
* Edits this Permission Overwrite. * Edits this Permission Overwrite.

View File

@@ -76,18 +76,27 @@ class Presence extends Base {
} }
_patch(data) { _patch(data) {
if ('status' in data) {
/** /**
* The status of this presence * The status of this presence
* @type {PresenceStatus} * @type {PresenceStatus}
*/ */
this.status = data.status ?? this.status ?? 'offline'; this.status = data.status;
} else {
this.status ??= 'offline';
}
if ('activities' in data) {
/** /**
* The activities of this presence * The activities of this presence
* @type {Activity[]} * @type {Activity[]}
*/ */
this.activities = data.activities?.map(activity => new Activity(this, activity)) ?? []; this.activities = data.activities.map(activity => new Activity(this, activity));
} else {
this.activities ??= [];
}
if ('client_status' in data) {
/** /**
* The devices this presence is on * The devices this presence is on
* @type {?Object} * @type {?Object}
@@ -95,7 +104,10 @@ class Presence extends Base {
* @property {?ClientPresenceStatus} mobile The current presence in the mobile application * @property {?ClientPresenceStatus} mobile The current presence in the mobile application
* @property {?ClientPresenceStatus} desktop The current presence in the desktop application * @property {?ClientPresenceStatus} desktop The current presence in the desktop application
*/ */
this.clientStatus = data.client_status ?? null; this.clientStatus = data.client_status;
} else {
this.clientStatus ??= null;
}
return this; return this;
} }

View File

@@ -34,48 +34,61 @@ class Role extends Base {
* @type {Snowflake} * @type {Snowflake}
*/ */
this.id = data.id; this.id = data.id;
if ('name' in data) {
/** /**
* The name of the role * The name of the role
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('color' in data) {
/** /**
* The base 10 color of the role * The base 10 color of the role
* @type {number} * @type {number}
*/ */
this.color = data.color; this.color = data.color;
}
if ('hoist' in data) {
/** /**
* If true, users that are part of this role will appear in a separate category in the users list * If true, users that are part of this role will appear in a separate category in the users list
* @type {boolean} * @type {boolean}
*/ */
this.hoist = data.hoist; this.hoist = data.hoist;
}
if ('position' in data) {
/** /**
* The raw position of the role from the API * The raw position of the role from the API
* @type {number} * @type {number}
*/ */
this.rawPosition = data.position; this.rawPosition = data.position;
}
if ('permissions' in data) {
/** /**
* The permissions of the role * The permissions of the role
* @type {Readonly<Permissions>} * @type {Readonly<Permissions>}
*/ */
this.permissions = new Permissions(BigInt(data.permissions)).freeze(); this.permissions = new Permissions(BigInt(data.permissions)).freeze();
}
if ('managed' in data) {
/** /**
* Whether or not the role is managed by an external service * Whether or not the role is managed by an external service
* @type {boolean} * @type {boolean}
*/ */
this.managed = data.managed; this.managed = data.managed;
}
if ('mentionable' in data) {
/** /**
* Whether or not the role can be mentioned by anyone * Whether or not the role can be mentioned by anyone
* @type {boolean} * @type {boolean}
*/ */
this.mentionable = data.mentionable; this.mentionable = data.mentionable;
}
/** /**
* Whether the role has been deleted * Whether the role has been deleted

View File

@@ -28,35 +28,47 @@ class StageInstance extends Base {
} }
_patch(data) { _patch(data) {
if ('guild_id' in data) {
/** /**
* The id of the guild associated with the stage channel * The id of the guild associated with the stage channel
* @type {Snowflake} * @type {Snowflake}
*/ */
this.guildId = data.guild_id; this.guildId = data.guild_id;
}
if ('channel_id' in data) {
/** /**
* The id of the channel associated with the stage channel * The id of the channel associated with the stage channel
* @type {Snowflake} * @type {Snowflake}
*/ */
this.channelId = data.channel_id; this.channelId = data.channel_id;
}
if ('topic' in data) {
/** /**
* The topic of the stage instance * The topic of the stage instance
* @type {string} * @type {string}
*/ */
this.topic = data.topic; this.topic = data.topic;
}
if ('privacy_level' in data) {
/** /**
* The privacy level of the stage instance * The privacy level of the stage instance
* @type {PrivacyLevel} * @type {PrivacyLevel}
*/ */
this.privacyLevel = PrivacyLevels[data.privacy_level]; this.privacyLevel = PrivacyLevels[data.privacy_level];
}
if ('discoverable_disabled' in data) {
/** /**
* Whether or not stage discovery is disabled * Whether or not stage discovery is disabled
* @type {?boolean} * @type {?boolean}
*/ */
this.discoverableDisabled = data.discoverable_disabled ?? null; this.discoverableDisabled = data.discoverable_disabled;
} else {
this.discoverableDisabled ??= null;
}
} }
/** /**

View File

@@ -26,65 +26,101 @@ class Sticker extends Base {
*/ */
this.id = sticker.id; this.id = sticker.id;
if ('description' in sticker) {
/** /**
* The description of the sticker * The description of the sticker
* @type {?string} * @type {?string}
*/ */
this.description = sticker.description ?? null; this.description = sticker.description;
} else {
this.description ??= null;
}
if ('type' in sticker) {
/** /**
* The type of the sticker * The type of the sticker
* @type {?StickerType} * @type {?StickerType}
*/ */
this.type = StickerTypes[sticker.type] ?? null; this.type = StickerTypes[sticker.type];
} else {
this.type ??= null;
}
if ('format_type' in sticker) {
/** /**
* The format of the sticker * The format of the sticker
* @type {StickerFormatType} * @type {StickerFormatType}
*/ */
this.format = StickerFormatTypes[sticker.format_type]; this.format = StickerFormatTypes[sticker.format_type];
}
if ('name' in sticker) {
/** /**
* The name of the sticker * The name of the sticker
* @type {string} * @type {string}
*/ */
this.name = sticker.name; this.name = sticker.name;
}
if ('pack_id' in sticker) {
/** /**
* The id of the pack the sticker is from, for standard stickers * The id of the pack the sticker is from, for standard stickers
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.packId = sticker.pack_id ?? null; this.packId = sticker.pack_id;
} else {
this.packId ??= null;
}
if ('tags' in sticker) {
/** /**
* An array of tags for the sticker * An array of tags for the sticker
* @type {?string[]} * @type {?string[]}
*/ */
this.tags = sticker.tags?.split(', ') ?? null; this.tags = sticker.tags.split(', ');
} else {
this.tags ??= null;
}
if ('available' in sticker) {
/** /**
* Whether or not the guild sticker is available * Whether or not the guild sticker is available
* @type {?boolean} * @type {?boolean}
*/ */
this.available = sticker.available ?? null; this.available = sticker.available;
} else {
this.available ??= null;
}
if ('guild_id' in sticker) {
/** /**
* The id of the guild that owns this sticker * The id of the guild that owns this sticker
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.guildId = sticker.guild_id ?? null; this.guildId = sticker.guild_id;
} else {
this.guildId ??= null;
}
if ('user' in sticker) {
/** /**
* The user that uploaded the guild sticker * The user that uploaded the guild sticker
* @type {?User} * @type {?User}
*/ */
this.user = sticker.user ? this.client.users._add(sticker.user) : null; this.user = this.client.users._add(sticker.user);
} else {
this.user ??= null;
}
if ('sort_value' in sticker) {
/** /**
* The standard sticker's sort order within its pack * The standard sticker's sort order within its pack
* @type {?number} * @type {?number}
*/ */
this.sortValue = sticker.sort_value ?? null; this.sortValue = sticker.sort_value;
} else {
this.sortValue ??= null;
}
} }
/** /**

View File

@@ -22,24 +22,33 @@ class Team extends Base {
*/ */
this.id = data.id; this.id = data.id;
if ('name' in data) {
/** /**
* The name of the Team * The name of the Team
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('icon' in data) {
/** /**
* The Team's icon hash * The Team's icon hash
* @type {?string} * @type {?string}
*/ */
this.icon = data.icon ?? null; this.icon = data.icon;
} else {
this.icon ??= null;
}
if ('owner_user_id' in data) {
/** /**
* The Team's owner id * The Team's owner id
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.ownerId = data.owner_user_id ?? null; this.ownerId = data.owner_user_id;
} else {
this.ownerId ??= null;
}
/** /**
* The Team's members * The Team's members
* @type {Collection<Snowflake, TeamMember>} * @type {Collection<Snowflake, TeamMember>}

View File

@@ -21,24 +21,30 @@ class TeamMember extends Base {
} }
_patch(data) { _patch(data) {
if ('permissions' in data) {
/** /**
* The permissions this Team Member has with regard to the team * The permissions this Team Member has with regard to the team
* @type {string[]} * @type {string[]}
*/ */
this.permissions = data.permissions; this.permissions = data.permissions;
}
if ('membership_state' in data) {
/** /**
* The permissions this Team Member has with regard to the team * The permissions this Team Member has with regard to the team
* @type {MembershipState} * @type {MembershipState}
*/ */
this.membershipState = MembershipStates[data.membership_state]; this.membershipState = MembershipStates[data.membership_state];
}
if ('user' in data) {
/** /**
* The user for this Team Member * The user for this Team Member
* @type {User} * @type {User}
*/ */
this.user = this.client.users._add(data.user); this.user = this.client.users._add(data.user);
} }
}
/** /**
* The Team Member's id * The Team Member's id

View File

@@ -51,11 +51,13 @@ class ThreadChannel extends Channel {
_patch(data, partial = false) { _patch(data, partial = false) {
super._patch(data); super._patch(data);
if ('name' in data) {
/** /**
* The name of the thread * The name of the thread
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('guild_id' in data) { if ('guild_id' in data) {
this.guildId = data.guild_id; this.guildId = data.guild_id;

View File

@@ -37,14 +37,16 @@ class ThreadMember extends Base {
} }
_patch(data) { _patch(data) {
this.joinedTimestamp = new Date(data.join_timestamp).getTime(); if ('join_timestamp' in data) this.joinedTimestamp = new Date(data.join_timestamp).getTime();
if ('flags' in data) {
/** /**
* The flags for this thread member * The flags for this thread member
* @type {ThreadMemberFlags} * @type {ThreadMemberFlags}
*/ */
this.flags = new ThreadMemberFlags(data.flags).freeze(); this.flags = new ThreadMemberFlags(data.flags).freeze();
} }
}
/** /**
* The guild member associated with this thread member * The guild member associated with this thread member

View File

@@ -31,12 +31,14 @@ class Typing extends Base {
} }
_patch(data) { _patch(data) {
if ('timestamp' in data) {
/** /**
* The UNIX timestamp in milliseconds the user started typing at * The UNIX timestamp in milliseconds the user started typing at
* @type {number} * @type {number}
*/ */
this.startedTimestamp = data.timestamp * 1_000; this.startedTimestamp = data.timestamp * 1_000;
} }
}
/** /**
* Indicates whether the status is received from a guild. * Indicates whether the status is received from a guild.

View File

@@ -41,8 +41,8 @@ class User extends Base {
* @type {?string} * @type {?string}
*/ */
this.username = data.username; this.username = data.username;
} else if (typeof this.username !== 'string') { } else {
this.username = null; this.username ??= null;
} }
if ('bot' in data) { if ('bot' in data) {
@@ -61,8 +61,8 @@ class User extends Base {
* @type {?string} * @type {?string}
*/ */
this.discriminator = data.discriminator; this.discriminator = data.discriminator;
} else if (typeof this.discriminator !== 'string') { } else {
this.discriminator = null; this.discriminator ??= null;
} }
if ('avatar' in data) { if ('avatar' in data) {
@@ -71,8 +71,8 @@ class User extends Base {
* @type {?string} * @type {?string}
*/ */
this.avatar = data.avatar; this.avatar = data.avatar;
} else if (typeof this.avatar !== 'string') { } else {
this.avatar = null; this.avatar ??= null;
} }
if ('banner' in data) { if ('banner' in data) {
@@ -82,8 +82,8 @@ class User extends Base {
* @type {?string} * @type {?string}
*/ */
this.banner = data.banner; this.banner = data.banner;
} else if (typeof this.banner !== 'string') { } else {
this.banner = null; this.banner ??= null;
} }
if ('accent_color' in data) { if ('accent_color' in data) {

View File

@@ -27,58 +27,104 @@ class VoiceState extends Base {
} }
_patch(data) { _patch(data) {
if ('deaf' in data) {
/** /**
* Whether this member is deafened server-wide * Whether this member is deafened server-wide
* @type {?boolean} * @type {?boolean}
*/ */
this.serverDeaf = data.deaf ?? null; this.serverDeaf = data.deaf;
} else {
this.serverDeaf ??= null;
}
if ('mute' in data) {
/** /**
* Whether this member is muted server-wide * Whether this member is muted server-wide
* @type {?boolean} * @type {?boolean}
*/ */
this.serverMute = data.mute ?? null; this.serverMute = data.mute;
} else {
this.serverMute ??= null;
}
if ('self_deaf' in data) {
/** /**
* Whether this member is self-deafened * Whether this member is self-deafened
* @type {?boolean} * @type {?boolean}
*/ */
this.selfDeaf = data.self_deaf ?? null; this.selfDeaf = data.self_deaf;
} else {
this.selfDeaf ??= null;
}
if ('self_mute' in data) {
/** /**
* Whether this member is self-muted * Whether this member is self-muted
* @type {?boolean} * @type {?boolean}
*/ */
this.selfMute = data.self_mute ?? null; this.selfMute = data.self_mute;
} else {
this.selfMute ??= null;
}
if ('self_video' in data) {
/** /**
* Whether this member's camera is enabled * Whether this member's camera is enabled
* @type {?boolean} * @type {?boolean}
*/ */
this.selfVideo = data.self_video ?? null; this.selfVideo = data.self_video;
} else {
this.selfVideo ??= null;
}
if ('session_id' in data) {
/** /**
* The session id for this member's connection * The session id for this member's connection
* @type {?string} * @type {?string}
*/ */
this.sessionId = data.session_id ?? null; this.sessionId = data.session_id;
} else {
this.sessionId ??= null;
}
if ('self_streaming' in data) {
/** /**
* Whether this member is streaming using "Screen Share" * Whether this member is streaming using "Screen Share"
* @type {boolean} * @type {boolean}
*/ */
this.streaming = data.self_stream ?? false; this.streaming = data.self_stream ?? false;
} else {
this.streaming ??= null;
}
if ('channel_id' in data) {
/** /**
* The {@link VoiceChannel} or {@link StageChannel} id the member is in * The {@link VoiceChannel} or {@link StageChannel} id the member is in
* @type {?Snowflake} * @type {?Snowflake}
*/ */
this.channelId = data.channel_id ?? null; this.channelId = data.channel_id;
} else {
this.channelId ??= null;
}
if ('suppress' in data) {
/** /**
* Whether this member is suppressed from speaking. This property is specific to stage channels only. * Whether this member is suppressed from speaking. This property is specific to stage channels only.
* @type {boolean} * @type {boolean}
*/ */
this.suppress = data.suppress; this.suppress = data.suppress;
}
if ('request_to_speak_timestamp' in data) {
/** /**
* The time at which the member requested to speak. This property is specific to stage channels only. * The time at which the member requested to speak. This property is specific to stage channels only.
* @type {?number} * @type {?number}
*/ */
this.requestToSpeakTimestamp = data.request_to_speak_timestamp this.requestToSpeakTimestamp = new Date(data.request_to_speak_timestamp).getTime();
? new Date(data.request_to_speak_timestamp).getTime() } else {
: null; this.requestToSpeakTimestamp ??= null;
}
return this; return this;
} }

View File

@@ -22,11 +22,13 @@ class Webhook {
} }
_patch(data) { _patch(data) {
if ('name' in data) {
/** /**
* The name of the webhook * The name of the webhook
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
/** /**
* The token for the webhook, unavailable for follower webhooks and webhooks owned by another application. * The token for the webhook, unavailable for follower webhooks and webhooks owned by another application.
@@ -35,11 +37,13 @@ class Webhook {
*/ */
Object.defineProperty(this, 'token', { value: data.token ?? null, writable: true, configurable: true }); Object.defineProperty(this, 'token', { value: data.token ?? null, writable: true, configurable: true });
if ('avatar' in data) {
/** /**
* The avatar for the webhook * The avatar for the webhook
* @type {?string} * @type {?string}
*/ */
this.avatar = data.avatar; this.avatar = data.avatar;
}
/** /**
* The webhook's id * The webhook's id
@@ -47,43 +51,59 @@ class Webhook {
*/ */
this.id = data.id; this.id = data.id;
if ('type' in data) {
/** /**
* The type of the webhook * The type of the webhook
* @type {WebhookType} * @type {WebhookType}
*/ */
this.type = WebhookTypes[data.type]; this.type = WebhookTypes[data.type];
}
if ('guild_id' in data) {
/** /**
* The guild the webhook belongs to * The guild the webhook belongs to
* @type {Snowflake} * @type {Snowflake}
*/ */
this.guildId = data.guild_id; this.guildId = data.guild_id;
}
if ('channel_id' in data) {
/** /**
* The channel the webhook belongs to * The channel the webhook belongs to
* @type {Snowflake} * @type {Snowflake}
*/ */
this.channelId = data.channel_id; this.channelId = data.channel_id;
}
if ('user' in data) {
/** /**
* The owner of the webhook * The owner of the webhook
* @type {?(User|APIUser)} * @type {?(User|APIUser)}
*/ */
this.owner = data.user ? this.client.users?._add(data.user) ?? data.user : null; this.owner = this.client.users?._add(data.user) ?? data.user;
} else {
this.owner ??= null;
}
if ('source_guild' in data) {
/** /**
* The source guild of the webhook * The source guild of the webhook
* @type {?(Guild|APIGuild)} * @type {?(Guild|APIGuild)}
*/ */
this.sourceGuild = data.source_guild this.sourceGuild = this.client.guilds?._add(data.source_guild, false) ?? data.source_guild;
? this.client.guilds?._add(data.source_guild, false) ?? data.source_guild } else {
: null; this.sourceGuild ??= null;
}
if ('source_channel' in data) {
/** /**
* The source channel of the webhook * The source channel of the webhook
* @type {?(Channel|APIChannel)} * @type {?(Channel|APIChannel)}
*/ */
this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel ?? null; this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
} else {
this.sourceChannel ??= null;
}
} }
/** /**

View File

@@ -37,17 +37,21 @@ class Widget extends Base {
*/ */
this.id = data.id; this.id = data.id;
if ('name' in data) {
/** /**
* The name of the guild. * The name of the guild.
* @type {string} * @type {string}
*/ */
this.name = data.name; this.name = data.name;
}
if ('instant_invite' in data) {
/** /**
* The invite of the guild. * The invite of the guild.
* @type {?string} * @type {?string}
*/ */
this.instantInvite = data.instant_invite; this.instantInvite = data.instant_invite;
}
/** /**
* The list of channels in the guild. * The list of channels in the guild.
@@ -68,12 +72,14 @@ class Widget extends Base {
this.members.set(member.id, new WidgetMember(this.client, member)); this.members.set(member.id, new WidgetMember(this.client, member));
} }
if ('presence_count' in data) {
/** /**
* The number of the members online. * The number of the members online.
* @type {number} * @type {number}
*/ */
this.presenceCount = data.presence_count; this.presenceCount = data.presence_count;
} }
}
/** /**
* Update the Widget. * Update the Widget.

View File

@@ -23,23 +23,35 @@ class Application extends Base {
*/ */
this.id = data.id; this.id = data.id;
if ('name' in data) {
/** /**
* The name of the application * The name of the application
* @type {?string} * @type {?string}
*/ */
this.name = data.name ?? this.name ?? null; this.name = data.name;
} else {
this.name ??= null;
}
if ('description' in data) {
/** /**
* The application's description * The application's description
* @type {?string} * @type {?string}
*/ */
this.description = data.description ?? this.description ?? null; this.description = data.description;
} else {
this.description ??= null;
}
if ('icon' in data) {
/** /**
* The application's icon hash * The application's icon hash
* @type {?string} * @type {?string}
*/ */
this.icon = data.icon ?? this.icon ?? null; this.icon = data.icon;
} else {
this.icon ??= null;
}
} }
/** /**