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;
/**
* The hash of the guild invite splash image
* @type {?string}
*/
this.splash = data.splash;
/** if ('splash' in data) {
* The hash of the guild banner /**
* @type {?string} * The hash of the guild invite splash image
*/ * @type {?string}
this.banner = data.banner; */
this.splash = data.splash;
}
/** if ('banner' in data) {
* The description of the guild, if any /**
* @type {?string} * The hash of the guild banner
*/ * @type {?string}
this.description = data.description; */
this.banner = data.banner;
}
/** if ('description' in data) {
* The verification level of the guild /**
* @type {VerificationLevel} * The description of the guild, if any
*/ * @type {?string}
this.verificationLevel = VerificationLevels[data.verification_level]; */
this.description = data.description;
}
/** if ('verification_level' in data) {
* The vanity invite code of the guild, if any /**
* @type {?string} * The verification level of the guild
*/ * @type {VerificationLevel}
this.vanityURLCode = data.vanity_url_code; */
this.verificationLevel = VerificationLevels[data.verification_level];
}
if ('vanity_url_code' in data) {
/**
* The vanity invite code of the guild, if any
* @type {?string}
*/
this.vanityURLCode = data.vanity_url_code;
}
if ('nsfw_level' in data) { if ('nsfw_level' in data) {
/** /**

View File

@@ -54,35 +54,47 @@ class ApplicationCommand extends Base {
} }
_patch(data) { _patch(data) {
/** if ('name' in data) {
* The name of this command /**
* @type {string} * The name of this command
*/ * @type {string}
this.name = data.name; */
this.name = data.name;
}
/** if ('description' in data) {
* The description of this command /**
* @type {string} * The description of this command
*/ * @type {string}
this.description = data.description; */
this.description = data.description;
}
/** if ('options' in data) {
* The options of this command /**
* @type {ApplicationCommandOption[]} * The options of this command
*/ * @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 /**
* @type {boolean} * Whether the command is enabled by default when the app is added to a guild
*/ * @type {boolean}
this.defaultPermission = data.default_permission; */
this.defaultPermission = data.default_permission;
}
/** if ('version' in data) {
* Autoincrementing version identifier updated during substantial record changes /**
* @type {Snowflake} * Autoincrementing version identifier updated during substantial record changes
*/ * @type {Snowflake}
this.version = data.version; */
this.version = data.version;
}
} }
/** /**

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,23 +12,29 @@ 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`. /**
* @type {?string} * The RTC region for this voice-based channel. This region is automatically selected if `null`.
*/ * @type {?string}
this.rtcRegion = data.rtc_region; */
this.rtcRegion = data.rtc_region;
}
/** if ('bitrate' in data) {
* The bitrate of this voice-based channel /**
* @type {number} * The bitrate of this voice-based channel
*/ * @type {number}
this.bitrate = data.bitrate; */
this.bitrate = data.bitrate;
}
/** if ('user_limit' in data) {
* The maximum amount of users allowed in this channel. /**
* @type {number} * The maximum amount of users allowed in this channel.
*/ * @type {number}
this.userLimit = data.user_limit; */
this.userLimit = data.user_limit;
}
} }
/** /**

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 /**
* @type {ApplicationFlags} * The flags this application has
*/ * @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 /**
* @type {?string} * The hash of the application's cover image
*/ * @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 /**
* @type {string[]} * The application's RPC origins, if enabled
*/ * @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 /**
* @type {?boolean} * If this application's bot requires a code grant when using the OAuth2 flow
*/ * @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 /**
* @type {?boolean} * If this application's bot is public
*/ * @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 /**
* @type {?Snowflake} * The channel's last message id, if one was sent
*/ * @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 /**
* @type {?number} * The timestamp when the last pinned message was pinned, if there was one
*/ * @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 /**
* @type {?string} * The hash of the guild discovery splash image
*/ * @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 /**
* @type {number} * The full amount of members in this guild
*/ * @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) /**
* @type {boolean} * Whether the guild is "large" (has more than {@link WebsocketOptions large_threshold} members, 50 by default)
*/ * @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) /**
* @type {?Snowflake} * The id of the application that created this guild (if applicable)
*/ * @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" /**
* @type {?number} * The time in seconds before a user is counted as "away from keyboard"
*/ * @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 /**
* @type {?Snowflake} * The id of the voice channel where AFK members are moved
*/ * @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 /**
* @type {?Snowflake} * The system channel's id
*/ * @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 /**
* @type {PremiumTier} * The premium tier of this guild
*/ * @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 /**
* @type {ExplicitContentFilterLevel} * The explicit content filter level of the guild
*/ * @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 /**
* @type {MFALevel} * The required MFA level for this guild
*/ * @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 /**
* @type {number} * The timestamp the client user joined the guild at
*/ * @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 /**
* @type {DefaultMessageNotificationLevel} * The default message notification level of the guild
*/ * @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 /**
* @type {Readonly<SystemChannelFlags>} * The value set for the guild's system channel flags
*/ * @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 /**
* @type {?Snowflake} * The rules channel's id for the guild
*/ * @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 /**
* @type {?Snowflake} * The community updates channel's id for the guild
*/ * @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` /**
* @type {string} * The preferred locale of the guild, defaults to `en-US`
* @see {@link https://discord.com/developers/docs/dispatch/field-values#predefined-field-values-accepted-locales} * @type {string}
*/ * @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 /**
* @type {User} * The user this ban applies to
*/ * @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 /**
* @type {string} * The name of this guild
*/ * @type {string}
this.name = data.name; */
this.name = data.name;
}
/** if ('icon' in data) {
* The icon of this guild /**
* @type {?string} * The icon of this guild
*/ * @type {?string}
this.icon = data.icon; */
this.icon = data.icon;
}
/** if ('splash' in data) {
* The splash icon of this guild /**
* @type {?string} * The splash icon of this guild
*/ * @type {?string}
this.splash = data.splash; */
this.splash = data.splash;
}
/** if ('discovery_splash' in data) {
* The discovery splash icon of this guild /**
* @type {?string} * The discovery splash icon of this guild
*/ * @type {?string}
this.discoverySplash = data.discovery_splash; */
this.discoverySplash = data.discovery_splash;
}
/** if ('features' in data) {
* An array of enabled guild features /**
* @type {Features[]} * An array of enabled guild 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 /**
* @type {number} * The approximate count of members in this guild
*/ * @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 /**
* @type {number} * The approximate count of online members in this guild
*/ * @type {number}
this.approximatePresenceCount = data.approximate_presence_count; */
this.approximatePresenceCount = data.approximate_presence_count;
}
/** if ('description' in data) {
* The description for this guild /**
* @type {?string} * The description for this guild
*/ * @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 /**
* @type {string} * The unique code of this template
*/ * @type {string}
this.code = data.code; */
this.code = data.code;
}
/** if ('name' in data) {
* The name of this template /**
* @type {string} * The name of this template
*/ * @type {string}
this.name = data.name; */
this.name = data.name;
}
/** if ('description' in data) {
* The description of this template /**
* @type {?string} * The description of this template
*/ * @type {?string}
this.description = data.description; */
this.description = data.description;
}
/** if ('usage_count' in data) {
* The amount of times this template has been used /**
* @type {number} * The amount of times this template has been used
*/ * @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 /**
* @type {Snowflake} * The id of the user that created this template
*/ * @type {Snowflake}
this.creatorId = data.creator_id; */
this.creatorId = data.creator_id;
}
/** if ('creator' in data) {
* The user that created this template /**
* @type {User} * The user that created this template
*/ * @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 /**
* @type {Date} * The time of when this template was created at
*/ * @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 /**
* @type {Date} * The time of when this template was last synced to the guild
*/ * @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 /**
* @type {Snowflake} * The id of the guild that this template belongs to
*/ * @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 /**
* @type {APIGuild} * The data of the guild that this template would create
*/ * @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 /**
* @type {?number} * The behavior of expiring subscribers
*/ * @type {?number}
this.expireBehavior = data.expire_behavior; */
this.expireBehavior = data.expire_behavior;
}
/** if ('expire_grace_period' in data) {
* The grace period before expiring subscribers /**
* @type {?number} * The grace period before expiring subscribers
*/ * @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 /**
* @type {?User} * The bot user for this application
*/ * @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 /**
* @type {?string} * The url of the application's terms of service
*/ * @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 /**
* @type {?string} * The url of the application's privacy policy
*/ * @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 /**
* @type {string[]} * The Array of RPC origin urls
*/ * @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 /**
* @type {?string} * The application's summary
*/ * @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 /**
* @type {?boolean} * Whether the application can be default hooked by the client
*/ * @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 /**
* @type {?string} * The hash of the application's cover image
*/ * @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 /**
* @type {?string} * The hex-encoded key for verification in interactions and the GameSDK's GetTicket
*/ * @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 /**
* @type {string} * The code for this invite
*/ * @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 /**
* @type {?number} * The approximate number of online members of the guild this invite is for
*/ * @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 /**
* @type {?number} * The approximate total number of members of the guild this invite is for
*/ * @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 /**
* @type {?boolean} * Whether or not this invite only grants temporary membership
*/ * @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 /**
* @type {?number} * The maximum age of the invite, in seconds, 0 if never expires
*/ * @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 /**
* @type {?number} * How many times this invite has been used
*/ * @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 /**
* @type {?number} * The maximum uses of this invite
*/ * @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 /**
* @type {?User} * The user who created this invite
*/ * @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 /**
* @type {?User} * The user whose stream to display for this voice channel stream invite
*/ * @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 /**
* @type {?IntegrationApplication} * The embedded application to open for this voice channel embedded application invite
*/ * @type {?IntegrationApplication}
this.targetApplication = data.target_application */
? new IntegrationApplication(this.client, data.target_application) this.targetApplication = new IntegrationApplication(this.client, data.target_application);
: null; } else {
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 /**
* @type {?TargetType} * The target type
*/ * @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 /**
* @type {Channel} * The channel the invite is for
*/ * @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 /**
* @type {?number} * The timestamp the invite was created at
*/ * @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 /**
* @type {?InviteStageInstance} * The stage instance data if there is a public {@link StageInstance} in the stage channel this invite is for
*/ * @type {?InviteStageInstance}
this.stageInstance = */
'stage_instance' in data this.stageInstance = new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id);
? new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id) } else {
: null; this.stageInstance ??= 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 /**
* @type {string} * The topic of the stage instance
*/ * @type {string}
this.topic = data.topic; */
this.topic = data.topic;
}
/** if ('participant_count' in data) {
* The number of users in the stage channel /**
* @type {number} * The number of users in the stage channel
*/ * @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 /**
* @type {number} * The number of users speaking in the stage channel
*/ * @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 /**
* @type {number} * The size of this attachment in bytes
*/ * @type {number}
this.size = data.size; */
this.size = data.size;
}
/** if ('url' in data) {
* The URL to this attachment /**
* @type {string} * The URL to this attachment
*/ * @type {string}
this.url = data.url; */
this.url = data.url;
}
/** if ('proxy_url' in data) {
* The Proxy URL to this attachment /**
* @type {string} * The Proxy URL to this attachment
*/ * @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) /**
* @type {?number} * The height of this attachment (if an image or video)
*/ * @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) /**
* @type {?number} * The width of this attachment (if an image or video)
*/ * @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 /**
* @type {?string} * This media type of this attachment
*/ * @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,23 +32,29 @@ class PermissionOverwrites extends Base {
*/ */
this.id = data.id; this.id = data.id;
/** if ('type' in data) {
* The type of this overwrite /**
* @type {OverwriteType} * The type of this overwrite
*/ * @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. /**
* @type {Readonly<Permissions>} * The permissions that are denied for the user or role.
*/ * @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. /**
* @type {Readonly<Permissions>} * The permissions that are allowed for the user or role.
*/ * @type {Readonly<Permissions>}
this.allow = new Permissions(BigInt(data.allow)).freeze(); */
this.allow = new Permissions(BigInt(data.allow)).freeze();
}
} }
/** /**

View File

@@ -76,26 +76,38 @@ class Presence extends Base {
} }
_patch(data) { _patch(data) {
/** if ('status' in data) {
* The status of this presence /**
* @type {PresenceStatus} * The status of this presence
*/ * @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 /**
* @type {Activity[]} * The activities of this presence
*/ * @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 /**
* @type {?Object} * The devices this presence is on
* @property {?ClientPresenceStatus} web The current presence in the web application * @type {?Object}
* @property {?ClientPresenceStatus} mobile The current presence in the mobile application * @property {?ClientPresenceStatus} web The current presence in the web application
* @property {?ClientPresenceStatus} desktop The current presence in the desktop application * @property {?ClientPresenceStatus} mobile The current presence in the mobile 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
* @type {string}
*/
this.name = data.name;
}
/** if ('color' in data) {
* The name of the role /**
* @type {string} * The base 10 color of the role
*/ * @type {number}
this.name = data.name; */
this.color = data.color;
}
/** if ('hoist' in data) {
* The base 10 color of the role /**
* @type {number} * If true, users that are part of this role will appear in a separate category in the users list
*/ * @type {boolean}
this.color = data.color; */
this.hoist = data.hoist;
}
/** if ('position' in data) {
* If true, users that are part of this role will appear in a separate category in the users list /**
* @type {boolean} * The raw position of the role from the API
*/ * @type {number}
this.hoist = data.hoist; */
this.rawPosition = data.position;
}
/** if ('permissions' in data) {
* The raw position of the role from the API /**
* @type {number} * The permissions of the role
*/ * @type {Readonly<Permissions>}
this.rawPosition = data.position; */
this.permissions = new Permissions(BigInt(data.permissions)).freeze();
}
/** if ('managed' in data) {
* The permissions of the role /**
* @type {Readonly<Permissions>} * Whether or not the role is managed by an external service
*/ * @type {boolean}
this.permissions = new Permissions(BigInt(data.permissions)).freeze(); */
this.managed = data.managed;
}
/** if ('mentionable' in data) {
* Whether or not the role is managed by an external service /**
* @type {boolean} * Whether or not the role can be mentioned by anyone
*/ * @type {boolean}
this.managed = data.managed; */
this.mentionable = data.mentionable;
/** }
* Whether or not the role can be mentioned by anyone
* @type {boolean}
*/
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 /**
* @type {Snowflake} * The id of the guild associated with the stage channel
*/ * @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 /**
* @type {Snowflake} * The id of the channel associated with the stage channel
*/ * @type {Snowflake}
this.channelId = data.channel_id; */
this.channelId = data.channel_id;
}
/** if ('topic' in data) {
* The topic of the stage instance /**
* @type {string} * The topic of the stage instance
*/ * @type {string}
this.topic = data.topic; */
this.topic = data.topic;
}
/** if ('privacy_level' in data) {
* The privacy level of the stage instance /**
* @type {PrivacyLevel} * The privacy level of the stage instance
*/ * @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 /**
* @type {?boolean} * Whether or not stage discovery is disabled
*/ * @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 /**
* @type {?string} * The description of the sticker
*/ * @type {?string}
this.description = sticker.description ?? null; */
this.description = sticker.description;
} else {
this.description ??= null;
}
/** if ('type' in sticker) {
* The type of the sticker /**
* @type {?StickerType} * The type of the sticker
*/ * @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 /**
* @type {StickerFormatType} * The format of the sticker
*/ * @type {StickerFormatType}
this.format = StickerFormatTypes[sticker.format_type]; */
this.format = StickerFormatTypes[sticker.format_type];
}
/** if ('name' in sticker) {
* The name of the sticker /**
* @type {string} * The name of the sticker
*/ * @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 /**
* @type {?Snowflake} * The id of the pack the sticker is from, for standard stickers
*/ * @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 /**
* @type {?string[]} * An array of tags for the sticker
*/ * @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 /**
* @type {?boolean} * Whether or not the guild sticker is available
*/ * @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 /**
* @type {?Snowflake} * The id of the guild that owns this sticker
*/ * @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 /**
* @type {?User} * The user that uploaded the guild sticker
*/ * @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 /**
* @type {?number} * The standard sticker's sort order within its pack
*/ * @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 /**
* @type {string} * The name of the Team
*/ * @type {string}
this.name = data.name; */
this.name = data.name;
}
/** if ('icon' in data) {
* The Team's icon hash /**
* @type {?string} * The Team's icon hash
*/ * @type {?string}
this.icon = data.icon ?? null; */
this.icon = data.icon;
/** } else {
* The Team's owner id this.icon ??= null;
* @type {?Snowflake} }
*/
this.ownerId = data.owner_user_id ?? null;
if ('owner_user_id' in data) {
/**
* The Team's owner id
* @type {?Snowflake}
*/
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,23 +21,29 @@ class TeamMember extends Base {
} }
_patch(data) { _patch(data) {
/** if ('permissions' in data) {
* The permissions this Team Member has with regard to the team /**
* @type {string[]} * The permissions this Team Member has with regard to the team
*/ * @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 /**
* @type {MembershipState} * The permissions this Team Member has with regard to the team
*/ * @type {MembershipState}
this.membershipState = MembershipStates[data.membership_state]; */
this.membershipState = MembershipStates[data.membership_state];
}
/** if ('user' in data) {
* The user for this Team Member /**
* @type {User} * The user for this Team Member
*/ * @type {User}
this.user = this.client.users._add(data.user); */
this.user = this.client.users._add(data.user);
}
} }
/** /**

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 /**
* @type {string} * The name of the thread
*/ * @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,13 +37,15 @@ 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 /**
* @type {ThreadMemberFlags} * The flags for this thread member
*/ * @type {ThreadMemberFlags}
this.flags = new ThreadMemberFlags(data.flags).freeze(); */
this.flags = new ThreadMemberFlags(data.flags).freeze();
}
} }
/** /**

View File

@@ -31,11 +31,13 @@ class Typing extends Base {
} }
_patch(data) { _patch(data) {
/** if ('timestamp' in data) {
* The UNIX timestamp in milliseconds the user started typing at /**
* @type {number} * The UNIX timestamp in milliseconds the user started typing at
*/ * @type {number}
this.startedTimestamp = data.timestamp * 1_000; */
this.startedTimestamp = data.timestamp * 1_000;
}
} }
/** /**

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 /**
* @type {?boolean} * Whether this member is deafened server-wide
*/ * @type {?boolean}
this.serverDeaf = data.deaf ?? null; */
/** this.serverDeaf = data.deaf;
* Whether this member is muted server-wide } else {
* @type {?boolean} this.serverDeaf ??= null;
*/ }
this.serverMute = data.mute ?? null;
/** if ('mute' in data) {
* Whether this member is self-deafened /**
* @type {?boolean} * Whether this member is muted server-wide
*/ * @type {?boolean}
this.selfDeaf = data.self_deaf ?? null; */
/** this.serverMute = data.mute;
* Whether this member is self-muted } else {
* @type {?boolean} this.serverMute ??= null;
*/ }
this.selfMute = data.self_mute ?? null;
/** if ('self_deaf' in data) {
* Whether this member's camera is enabled /**
* @type {?boolean} * Whether this member is self-deafened
*/ * @type {?boolean}
this.selfVideo = data.self_video ?? null; */
/** this.selfDeaf = data.self_deaf;
* The session id for this member's connection } else {
* @type {?string} this.selfDeaf ??= null;
*/ }
this.sessionId = data.session_id ?? null;
/** if ('self_mute' in data) {
* Whether this member is streaming using "Screen Share" /**
* @type {boolean} * Whether this member is self-muted
*/ * @type {?boolean}
this.streaming = data.self_stream ?? false; */
/** this.selfMute = data.self_mute;
* The {@link VoiceChannel} or {@link StageChannel} id the member is in } else {
* @type {?Snowflake} this.selfMute ??= null;
*/ }
this.channelId = data.channel_id ?? null;
/** if ('self_video' in data) {
* Whether this member is suppressed from speaking. This property is specific to stage channels only. /**
* @type {boolean} * Whether this member's camera is enabled
*/ * @type {?boolean}
this.suppress = data.suppress; */
/** this.selfVideo = data.self_video;
* The time at which the member requested to speak. This property is specific to stage channels only. } else {
* @type {?number} this.selfVideo ??= null;
*/ }
this.requestToSpeakTimestamp = data.request_to_speak_timestamp
? new Date(data.request_to_speak_timestamp).getTime() if ('session_id' in data) {
: null; /**
* The session id for this member's connection
* @type {?string}
*/
this.sessionId = data.session_id;
} else {
this.sessionId ??= null;
}
if ('self_streaming' in data) {
/**
* Whether this member is streaming using "Screen Share"
* @type {boolean}
*/
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
* @type {?Snowflake}
*/
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.
* @type {boolean}
*/
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.
* @type {?number}
*/
this.requestToSpeakTimestamp = new Date(data.request_to_speak_timestamp).getTime();
} else {
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 /**
* @type {string} * The name of the webhook
*/ * @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 /**
* @type {?string} * The avatar for the webhook
*/ * @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 /**
* @type {WebhookType} * The type of the webhook
*/ * @type {WebhookType}
this.type = WebhookTypes[data.type]; */
this.type = WebhookTypes[data.type];
}
/** if ('guild_id' in data) {
* The guild the webhook belongs to /**
* @type {Snowflake} * The guild the webhook belongs to
*/ * @type {Snowflake}
this.guildId = data.guild_id; */
this.guildId = data.guild_id;
}
/** if ('channel_id' in data) {
* The channel the webhook belongs to /**
* @type {Snowflake} * The channel the webhook belongs to
*/ * @type {Snowflake}
this.channelId = data.channel_id; */
this.channelId = data.channel_id;
}
/** if ('user' in data) {
* The owner of the webhook /**
* @type {?(User|APIUser)} * The owner of the webhook
*/ * @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 /**
* @type {?(Guild|APIGuild)} * The source guild of the webhook
*/ * @type {?(Guild|APIGuild)}
this.sourceGuild = data.source_guild */
? this.client.guilds?._add(data.source_guild, false) ?? data.source_guild this.sourceGuild = this.client.guilds?._add(data.source_guild, false) ?? data.source_guild;
: null; } else {
this.sourceGuild ??= null;
}
/** if ('source_channel' in data) {
* The source channel of the webhook /**
* @type {?(Channel|APIChannel)} * The source channel of the webhook
*/ * @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. /**
* @type {string} * The name of the guild.
*/ * @type {string}
this.name = data.name; */
this.name = data.name;
}
/** if ('instant_invite' in data) {
* The invite of the guild. /**
* @type {?string} * The invite of the guild.
*/ * @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,11 +72,13 @@ 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. /**
* @type {number} * The number of the members online.
*/ * @type {number}
this.presenceCount = data.presence_count; */
this.presenceCount = data.presence_count;
}
} }
/** /**

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 /**
* @type {?string} * The name of the application
*/ * @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 /**
* @type {?string} * The application's description
*/ * @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 /**
* @type {?string} * The application's icon hash
*/ * @type {?string}
this.icon = data.icon ?? this.icon ?? null; */
this.icon = data.icon;
} else {
this.icon ??= null;
}
} }
/** /**