diff --git a/.eslintrc.yml b/.eslintrc.yml index b73747ad2..596cc3d6f 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -19,6 +19,7 @@ rules: comma-dangle: - 2 - never + curly: 2 eol-last: - 2 - always diff --git a/lib/structures/ExtendedUser.js b/lib/structures/ExtendedUser.js index 98ee15b63..2c866e1bb 100644 --- a/lib/structures/ExtendedUser.js +++ b/lib/structures/ExtendedUser.js @@ -17,10 +17,18 @@ class ExtendedUser extends User { update(data) { super.update(data); - if(data.email !== undefined) this.email = data.email; - if(data.verified !== undefined) this.verified = data.verified; - if(data.mfa_enabled !== undefined) this.mfaEnabled = data.mfa_enabled; - if(data.premium !== undefined) this.premium = data.premium; + if(data.email !== undefined) { + this.email = data.email; + } + if(data.verified !== undefined) { + this.verified = data.verified; + } + if(data.mfa_enabled !== undefined) { + this.mfaEnabled = data.mfa_enabled; + } + if(data.premium !== undefined) { + this.premium = data.premium; + } } toJSON(props = []) { diff --git a/lib/structures/GroupChannel.js b/lib/structures/GroupChannel.js index c71b19924..76c5d0183 100644 --- a/lib/structures/GroupChannel.js +++ b/lib/structures/GroupChannel.js @@ -30,9 +30,15 @@ class GroupChannel extends PrivateChannel { // (╯°□°)╯︵ ┻━┻ } update(data) { - if(data.name !== undefined) this.name = data.name; - if(data.owner_id !== undefined) this.ownerID = data.owner_id; - if(data.icon !== undefined) this.icon = data.icon; + if(data.name !== undefined) { + this.name = data.name; + } + if(data.owner_id !== undefined) { + this.ownerID = data.owner_id; + } + if(data.icon !== undefined) { + this.icon = data.icon; + } } /** diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index af0381356..631c0b697 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -122,29 +122,75 @@ class Guild extends Base { } update(data) { - if(data.name !== undefined) this.name = data.name; - if(data.verification_level !== undefined) this.verificationLevel = data.verification_level; - if(data.splash !== undefined) this.splash = data.splash; - if(data.banner !== undefined) this.banner = data.banner; - if(data.region !== undefined) this.region = data.region; - if(data.owner_id !== undefined) this.ownerID = data.owner_id; - if(data.icon !== undefined) this.icon = data.icon; - if(data.features !== undefined) this.features = data.features; - if(data.emojis !== undefined) this.emojis = data.emojis; - if(data.afk_channel_id !== undefined) this.afkChannelID = data.afk_channel_id; - if(data.afk_timeout !== undefined) this.afkTimeout = data.afk_timeout; - if(data.default_message_notifications !== undefined) this.defaultNotifications = data.default_message_notifications; - if(data.mfa_level !== undefined) this.mfaLevel = data.mfa_level; - if(data.large !== undefined) this.large = data.large; - if(data.max_presences !== undefined) this.maxPresences = data.max_presences; - if(data.explicit_content_filter !== undefined) this.explicitContentFilter = data.explicit_content_filter; - if(data.system_channel_id !== undefined) this.systemChannelID = data.system_channel_id; - if(data.premium_tier !== undefined) this.premiumTier = data.premium_tier; - if(data.premium_subscription_count !== undefined) this.premiumSubscriptionCount = data.premium_subscription_count; - if(data.vanity_url_code !== undefined) this.vanityURL = data.vanity_url_code; - if(data.preferred_locale !== undefined) this.preferredLocale = data.preferred_locale; - if(data.description !== undefined) this.description = data.description; - if(data.max_members !== undefined) this.maxMembers = data.max_members; + if(data.name !== undefined) { + this.name = data.name; + } + if(data.verification_level !== undefined) { + this.verificationLevel = data.verification_level; + } + if(data.splash !== undefined) { + this.splash = data.splash; + } + if(data.banner !== undefined) { + this.banner = data.banner; + } + if(data.region !== undefined) { + this.region = data.region; + } + if(data.owner_id !== undefined) { + this.ownerID = data.owner_id; + } + if(data.icon !== undefined) { + this.icon = data.icon; + } + if(data.features !== undefined) { + this.features = data.features; + } + if(data.emojis !== undefined) { + this.emojis = data.emojis; + } + if(data.afk_channel_id !== undefined) { + this.afkChannelID = data.afk_channel_id; + } + if(data.afk_timeout !== undefined) { + this.afkTimeout = data.afk_timeout; + } + if(data.default_message_notifications !== undefined) { + this.defaultNotifications = data.default_message_notifications; + } + if(data.mfa_level !== undefined) { + this.mfaLevel = data.mfa_level; + } + if(data.large !== undefined) { + this.large = data.large; + } + if(data.max_presences !== undefined) { + this.maxPresences = data.max_presences; + } + if(data.explicit_content_filter !== undefined) { + this.explicitContentFilter = data.explicit_content_filter; + } + if(data.system_channel_id !== undefined) { + this.systemChannelID = data.system_channel_id; + } + if(data.premium_tier !== undefined) { + this.premiumTier = data.premium_tier; + } + if(data.premium_subscription_count !== undefined) { + this.premiumSubscriptionCount = data.premium_subscription_count; + } + if(data.vanity_url_code !== undefined) { + this.vanityURL = data.vanity_url_code; + } + if(data.preferred_locale !== undefined) { + this.preferredLocale = data.preferred_locale; + } + if(data.description !== undefined) { + this.description = data.description; + } + if(data.max_members !== undefined) { + this.maxMembers = data.max_members; + } } /** diff --git a/lib/structures/GuildChannel.js b/lib/structures/GuildChannel.js index 1beab8ff7..b456e1d01 100644 --- a/lib/structures/GuildChannel.js +++ b/lib/structures/GuildChannel.js @@ -30,10 +30,18 @@ class GuildChannel extends Channel { } update(data) { - if(data.type !== undefined) this.type = data.type; - if(data.name !== undefined) this.name = data.name; - if(data.position !== undefined) this.position = data.position; - if(data.parent_id !== undefined) this.parentID = data.parent_id; + if(data.type !== undefined) { + this.type = data.type; + } + if(data.name !== undefined) { + this.name = data.name; + } + if(data.position !== undefined) { + this.position = data.position; + } + if(data.parent_id !== undefined) { + this.parentID = data.parent_id; + } this.nsfw = (this.name.length === 4 ? this.name === "nsfw" : this.name.startsWith("nsfw-")) || data.nsfw; if(data.permission_overwrites) { this.permissionOverwrites = new Collection(PermissionOverwrite); diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 3ea56ac73..994689013 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -60,10 +60,18 @@ class Member extends Base { update(data) { this.status = data.status !== undefined ? data.status : this.status || "offline"; this.game = data.game !== undefined ? data.game : this.game || null; - if(data.joined_at !== undefined) this.joinedAt = Date.parse(data.joined_at); - if(data.client_status !== undefined) this.clientStatus = Object.assign({web: "offline", desktop: "offline", mobile: "offline"}, data.client_status); - if(data.activities !== undefined) this.activities = data.activities; - if(data.premium_since !== undefined) this.premiumSince = data.premium_since; + if(data.joined_at !== undefined) { + this.joinedAt = Date.parse(data.joined_at); + } + if(data.client_status !== undefined) { + this.clientStatus = Object.assign({web: "offline", desktop: "offline", mobile: "offline"}, data.client_status); + } + if(data.activities !== undefined) { + this.activities = data.activities; + } + if(data.premium_since !== undefined) { + this.premiumSince = data.premium_since; + } if("mute" in data) { const state = this.guild.voiceStates.get(this.id); diff --git a/lib/structures/Message.js b/lib/structures/Message.js index ab95e5ea2..d44b845cb 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -82,49 +82,77 @@ class Message extends Base { } else { this.member = null; } - if(this.type === MessageTypes.DEFAULT || this.type === undefined); - else if(this.type === MessageTypes.RECIPIENT_ADD) { - data.content = `${this.author.mention} added <@${data.mentions[0].id}>.`; - } else if(this.type === MessageTypes.RECIPIENT_REMOVE) { - if(this.author.id === data.mentions[0].id) { - data.content = `@${this.author.username} left the group.`; - } else { - data.content = `${this.author.mention} removed @${data.mentions[0].username}.`; + + switch(this.type) { + case MessageTypes.DEFAULT: { + break; } - } else if(this.type === MessageTypes.CALL) { // (╯°□°)╯︵ ┻━┻ - if(data.call.ended_timestamp) { - if((!this.channel.lastCall || this.channel.lastCall.endedTimestamp < Date.parse(data.call.ended_timestamp))) { - data.call.id = this.id; - this.channel.lastCall = new Call(data.call, this.channel); - } - if(data.call.participants.includes(client.user.id)) { - data.content = `You missed a call from ${this.author.mention}.`; + case MessageTypes.RECIPIENT_ADD: { + data.content = `${this.author.mention} added <@${data.mentions[0].id}>.`; + break; + } + case MessageTypes.RECIPIENT_REMOVE: { + if(this.author.id === data.mentions[0].id) { + data.content = `@${this.author.username} left the group.`; } else { - data.content = `${this.author.mention} started a call.`; + data.content = `${this.author.mention} removed @${data.mentions[0].username}.`; } - } else { - if(!this.channel.call) { - data.call.id = this.id; - this.channel.call = new Call(data.call, this.channel); + break; + } + case MessageTypes.CALL: { + if(data.call.ended_timestamp) { + if((!this.channel.lastCall || this.channel.lastCall.endedTimestamp < Date.parse(data.call.ended_timestamp))) { + data.call.id = this.id; + this.channel.lastCall = new Call(data.call, this.channel); + } + if(data.call.participants.includes(client.user.id)) { + data.content = `You missed a call from ${this.author.mention}.`; + } else { + data.content = `${this.author.mention} started a call.`; + } + } else { + if(!this.channel.call) { + data.call.id = this.id; + this.channel.call = new Call(data.call, this.channel); + } + data.content = `${this.author.mention} started a call. — Join the call.`; } - data.content = `${this.author.mention} started a call. — Join the call.`; + break; + } + case MessageTypes.CHANNEL_NAME_CHANGE: { + data.content = `${this.author.mention} changed the channel name: ${data.content}`; + break; + } + case MessageTypes.CHANNEL_ICON_CHANGE: { + data.content = `${this.author.mention} changed the channel icon.`; + break; + } + case MessageTypes.CHANNEL_PINNED_MESSAGE: { + data.content = `${this.author.mention} pinned a message to this channel. See all the pins.`; + break; + } + case MessageTypes.GUILD_MEMBER_JOIN: { + data.content = SystemJoinMessages[~~(this.createdAt % SystemJoinMessages.length)].replace(/%user%/g, this.author.mention); + break; + } + case MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION: { + data.content = `${this.author.mention} just boosted the server!`; + break; + } + case MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1: + case MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2: + case MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3: { + data.content = `${this.author.mention} just boosted the server! ${this.channel.guild ? this.channel.guild.name : data.guild_id} has achieved **Level ${this.type - 8}!**`; + break; + } + case MessageTypes.CHANNEL_FOLLOW_ADD: { + data.content = `${this.author.mention} has added ${data.content} to this channel`; + break; + } + default: { + client.emit("warn", `Unhandled MESSAGE_CREATE type: ${JSON.stringify(data, null, 2)}`); + break; } - } else if(this.type === MessageTypes.CHANNEL_NAME_CHANGE) { - data.content = `${this.author.mention} changed the channel name: ${data.content}`; - } else if(this.type === MessageTypes.CHANNEL_ICON_CHANGE) { - data.content = `${this.author.mention} changed the channel icon.`; - } else if(this.type === MessageTypes.CHANNEL_PINNED_MESSAGE) { - data.content = `${this.author.mention} pinned a message to this channel. See all the pins.`; - } else if(this.type === MessageTypes.GUILD_MEMBER_JOIN) { - data.content = SystemJoinMessages[~~(this.createdAt % SystemJoinMessages.length)].replace(/%user%/g, this.author.mention); - } else if(this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION) { - data.content = `${this.author.mention} just boosted the server!`; - } else if(this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 || this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 || this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3) { - data.content = `${this.author.mention} just boosted the server! ${this.channel.guild ? this.channel.guild.name : data.guild_id} has achieved **Level ${this.type - 8}!**`; - } else if(this.type === MessageTypes.CHANNEL_FOLLOW_ADD) { - data.content = `${this.author.mention} has added ${data.content} to this channel`; - } else { - client.emit("warn", "Unhandled MESSAGE_CREATE type: " + JSON.stringify(data, null, 2)); } this.update(data, client); @@ -150,13 +178,27 @@ class Message extends Base { this.roleMentions = data.mention_roles; } - if(data.pinned !== undefined) this.pinned = !!data.pinned; - if(data.edited_timestamp != undefined) this.editedTimestamp = Date.parse(data.edited_timestamp); - if(data.tts !== undefined) this.tts = data.tts; - if(data.attachments !== undefined) this.attachments = data.attachments; - if(data.embeds !== undefined) this.embeds = data.embeds; - if(data.activity !== undefined) this.activity = data.activity; - if(data.application !== undefined) this.application = data.application; + if(data.pinned !== undefined) { + this.pinned = !!data.pinned; + } + if(data.edited_timestamp != undefined) { + this.editedTimestamp = Date.parse(data.edited_timestamp); + } + if(data.tts !== undefined) { + this.tts = data.tts; + } + if(data.attachments !== undefined) { + this.attachments = data.attachments; + } + if(data.embeds !== undefined) { + this.embeds = data.embeds; + } + if(data.activity !== undefined) { + this.activity = data.activity; + } + if(data.application !== undefined) { + this.application = data.application; + } if(data.reactions) { data.reactions.forEach((reaction) => { @@ -169,9 +211,7 @@ class Message extends Base { } get cleanContent() { - let cleanContent = this.content; - - cleanContent = cleanContent.replace(/<(:\w+:)[0-9]+>/g, "$1"); + let cleanContent = this.content.replace(/<(:\w+:)[0-9]+>/g, "$1"); let authorName = this.author.username; if(this.channel.guild) { diff --git a/lib/structures/Role.js b/lib/structures/Role.js index 304ffacb3..5087fc0c5 100644 --- a/lib/structures/Role.js +++ b/lib/structures/Role.js @@ -26,13 +26,27 @@ class Role extends Base { } update(data) { - if(data.name !== undefined) this.name = data.name; - if(data.mentionable !== undefined) this.mentionable = data.mentionable; - if(data.managed !== undefined) this.managed = data.managed; - if(data.hoist !== undefined) this.hoist = data.hoist; - if(data.color !== undefined) this.color = data.color; - if(data.position !== undefined) this.position = data.position; - if(data.permissions !== undefined) this.permissions = new Permission(data.permissions); + if(data.name !== undefined) { + this.name = data.name; + } + if(data.mentionable !== undefined) { + this.mentionable = data.mentionable; + } + if(data.managed !== undefined) { + this.managed = data.managed; + } + if(data.hoist !== undefined) { + this.hoist = data.hoist; + } + if(data.color !== undefined) { + this.color = data.color; + } + if(data.position !== undefined) { + this.position = data.position; + } + if(data.permissions !== undefined) { + this.permissions = new Permission(data.permissions); + } } /** diff --git a/lib/structures/TextChannel.js b/lib/structures/TextChannel.js index ef268e3cd..ff781ca03 100644 --- a/lib/structures/TextChannel.js +++ b/lib/structures/TextChannel.js @@ -34,8 +34,12 @@ class TextChannel extends GuildChannel { update(data) { super.update(data); - if(data.rate_limit_per_user !== undefined) this.rateLimitPerUser = data.rate_limit_per_user; - if(data.topic !== undefined) this.topic = data.topic; + if(data.rate_limit_per_user !== undefined) { + this.rateLimitPerUser = data.rate_limit_per_user; + } + if(data.topic !== undefined) { + this.topic = data.topic; + } } /** diff --git a/lib/structures/User.js b/lib/structures/User.js index 2776ca0f8..a6042baff 100644 --- a/lib/structures/User.js +++ b/lib/structures/User.js @@ -31,9 +31,15 @@ class User extends Base { } update(data) { - if(data.avatar !== undefined) this.avatar = data.avatar; - if(data.username !== undefined) this.username = data.username; - if(data.discriminator !== undefined) this.discriminator = data.discriminator; + if(data.avatar !== undefined) { + this.avatar = data.avatar; + } + if(data.username !== undefined) { + this.username = data.username; + } + if(data.discriminator !== undefined) { + this.discriminator = data.discriminator; + } } get mention() { diff --git a/lib/structures/VoiceChannel.js b/lib/structures/VoiceChannel.js index 4dcf6d245..d5b5f2f96 100644 --- a/lib/structures/VoiceChannel.js +++ b/lib/structures/VoiceChannel.js @@ -30,8 +30,12 @@ class VoiceChannel extends GuildChannel { update(data) { super.update(data); - if(data.bitrate !== undefined) this.bitrate = data.bitrate; - if(data.user_limit !== undefined) this.userLimit = data.user_limit; + if(data.bitrate !== undefined) { + this.bitrate = data.bitrate; + } + if(data.user_limit !== undefined) { + this.userLimit = data.user_limit; + } } /**