Skip to content

Commit

Permalink
Add curly linter rule (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
apacheli authored and abalabahaha committed Dec 1, 2019
1 parent 6185094 commit 07ba8f2
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 100 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Expand Up @@ -19,6 +19,7 @@ rules:
comma-dangle:
- 2
- never
curly: 2
eol-last:
- 2
- always
Expand Down
16 changes: 12 additions & 4 deletions lib/structures/ExtendedUser.js
Expand Up @@ -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 = []) {
Expand Down
12 changes: 9 additions & 3 deletions lib/structures/GroupChannel.js
Expand Up @@ -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;
}
}

/**
Expand Down
92 changes: 69 additions & 23 deletions lib/structures/Guild.js
Expand Up @@ -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;
}
}

/**
Expand Down
16 changes: 12 additions & 4 deletions lib/structures/GuildChannel.js
Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions lib/structures/Member.js
Expand Up @@ -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);
Expand Down
136 changes: 88 additions & 48 deletions lib/structures/Message.js
Expand Up @@ -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);
Expand All @@ -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) => {
Expand All @@ -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) {
Expand Down
28 changes: 21 additions & 7 deletions lib/structures/Role.js
Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 07ba8f2

Please sign in to comment.