Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint rules #549

Merged
merged 18 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,26 @@ rules:
semi: [2, "always"]
require-atomic-updates: 1
no-prototype-builtins: 0
quotes: [2, "double"]
eol-last: [2, "always"]
no-trailing-spaces: 2
keyword-spacing: [2, {
"after": true,
"overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false },
"catch": { "after": false },
"switch": { "after": false }
}
}]
brace-style: [2, "1tbs", { "allowSingleLine": false }]
object-curly-spacing: [2, "never"]
array-bracket-spacing: [2, "never"]
comma-dangle: [2, "never"]
arrow-parens: 2
indent: [2, 4, {
"SwitchCase": 1,
"ignoreComments": false
}]
object-shorthand: [2, "consistent-as-needed"]
8 changes: 4 additions & 4 deletions examples/basicCommands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Eris = require("eris");

// Replace BOT_TOKEN with your bot account's token
var bot = new Eris.CommandClient("BOT_TOKEN", {}, {
const bot = new Eris.CommandClient("BOT_TOKEN", {}, {
description: "A test bot made with Eris",
owner: "somebody",
prefix: "!"
Expand All @@ -25,11 +25,11 @@ bot.registerCommand("pong", ["Pang!", "Peng!", "Ping!", "Pung!"], { // Make a po
fullDescription: "This command could also be used to check if the bot is up. Or entertainment when you're bored."
});

var echoCommand = bot.registerCommand("echo", (msg, args) => { // Make an echo command
const echoCommand = bot.registerCommand("echo", (msg, args) => { // Make an echo command
if(args.length === 0) { // If the user just typed "!echo", say "Invalid input"
return "Invalid input";
}
var text = args.join(" "); // Make a string of the text after the command label
const text = args.join(" "); // Make a string of the text after the command label
return text; // Return the generated string
}, {
description: "Make the bot say something",
Expand All @@ -41,7 +41,7 @@ echoCommand.registerSubcommand("reverse", (msg, args) => { // Make a reverse sub
if(args.length === 0) { // If the user just typed "!echo reverse", say "Invalid input"
return "Invalid input";
}
var text = args.join(" "); // Make a string of the text after the command label
let text = args.join(" "); // Make a string of the text after the command label
text = text.split("").reverse().join(""); // Reverse the string
return text; // Return the generated string
}, {
Expand Down
2 changes: 1 addition & 1 deletion examples/embed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Eris = require("eris");

var bot = new Eris("BOT_TOKEN");
const bot = new Eris("BOT_TOKEN");
// Replace BOT_TOKEN with your bot account's token

bot.on("ready", () => { // When the bot is ready
Expand Down
2 changes: 1 addition & 1 deletion examples/pingpong.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Eris = require("eris");

var bot = new Eris("BOT_TOKEN");
const bot = new Eris("BOT_TOKEN");
// Replace BOT_TOKEN with your bot account's token

bot.on("ready", () => { // When the bot is ready
Expand Down
7 changes: 3 additions & 4 deletions examples/playFile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const Eris = require("eris");
const FS = require("fs");

var bot = new Eris("BOT_TOKEN");
const bot = new Eris("BOT_TOKEN");
// Replace BOT_TOKEN with your bot account's token
var playCommand = "!play";
const playCommand = "!play";

bot.on("ready", () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"
Expand All @@ -23,7 +22,7 @@ bot.on("messageCreate", (msg) => { // When a message is created
bot.createMessage(msg.channel.id, "You are not in a voice channel.");
return;
}
var filename = msg.content.substring(playCommand.length + 1); // Get the filename
const filename = msg.content.substring(playCommand.length + 1); // Get the filename
bot.joinVoiceChannel(msg.member.voiceState.channelID).catch((err) => { // Join the user's voice channel
bot.createMessage(msg.channel.id, "Error joining voice channel: " + err.message); // Notify the user if there is an error
console.log(err); // Log the error
Expand Down
2 changes: 1 addition & 1 deletion examples/reactionButtons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Eris = require("eris");

// Replace BOT_TOKEN with your bot account's token
var bot = new Eris.CommandClient("BOT_TOKEN", {}, {
const bot = new Eris.CommandClient("BOT_TOKEN", {}, {
description: "A test bot made with Eris",
owner: "somebody",
prefix: "!"
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Eris.Shard = require("./lib/gateway/Shard");
Eris.SharedStream = require("./lib/voice/SharedStream");
Eris.TextChannel = require("./lib/structures/TextChannel");
Eris.User = require("./lib/structures/User");
Eris.VERSION = require('./package.json').version;
Eris.VERSION = require("./package.json").version;
Eris.VoiceChannel = require("./lib/structures/VoiceChannel");
Eris.VoiceConnection = require("./lib/voice/VoiceConnection");
Eris.VoiceConnectionManager = require("./lib/voice/VoiceConnectionManager");
Eris.VoiceState = require("./lib/structures/VoiceState");

Object.keys(Eris).filter(prop => Eris.hasOwnProperty(prop) && typeof Eris[prop] === "function" && !(Eris[prop] instanceof Eris.Base)).forEach(prop => {
Object.keys(Eris).filter((prop) => Eris.hasOwnProperty(prop) && typeof Eris[prop] === "function" && !(Eris[prop] instanceof Eris.Base)).forEach((prop) => {
Eris[prop].prototype.toString = Eris.Base.prototype.toString;
});

Expand Down
34 changes: 17 additions & 17 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Client extends EventEmitter {
throw new TypeError(`Invalid default image size: ${defaultImageSize}`);
}
// Set HTTP Agent on Websockets if not already set
if (this.options.agent && !(this.options.ws && this.options.ws.agent)) {
if(this.options.agent && !(this.options.ws && this.options.ws.agent)) {
this.options.ws = this.options.ws || {};
this.options.ws.agent = this.options.agent;
}
Expand Down Expand Up @@ -205,8 +205,8 @@ class Client extends EventEmitter {
this.gatewayURL += "&compress=zlib-stream";
}

if (this.options.maxShards === "auto") {
if (!data.shards) {
if(this.options.maxShards === "auto") {
if(!data.shards) {
throw new Error("Failed to autoshard due to lack of data from Discord.");
}
this.options.maxShards = data.shards;
Expand Down Expand Up @@ -300,9 +300,9 @@ class Client extends EventEmitter {
}

/**
* Closes a voice connection with a guild ID
* @arg {String} guildID The ID of the guild
*/
* Closes a voice connection with a guild ID
* @arg {String} guildID The ID of the guild
*/
closeVoiceConnection(guildID) {
this.shards.get(this.guildShardMap[guildID] || 0).sendWS(Constants.GatewayOPCodes.VOICE_STATE_UPDATE, {
guild_id: guildID || null,
Expand Down Expand Up @@ -360,7 +360,7 @@ class Client extends EventEmitter {
throw new Error(`Invalid channel ID: ${channelID}`);
}

if (this.channelGuildMap[channelID] && this.guilds.get(this.channelGuildMap[channelID])) {
if(this.channelGuildMap[channelID] && this.guilds.get(this.channelGuildMap[channelID])) {
return this.guilds.get(this.channelGuildMap[channelID]).channels.get(channelID);
}
return this.privateChannels.get(channelID) || this.groupChannels.get(channelID);
Expand Down Expand Up @@ -580,7 +580,7 @@ class Client extends EventEmitter {
temporary: options.temporary,
unique: options.unique,
reason: reason
}).then(invite => new Invite(invite, this));
}).then((invite) => new Invite(invite, this));
}

/**
Expand Down Expand Up @@ -979,7 +979,7 @@ class Client extends EventEmitter {
* @arg {String} [around] Get messages around this message ID (does not work with limit > 100)
* @returns {Promise<Message[]>}
*/
async getMessages(channelID, limit, before, after, around) {
async getMessages(channelID, limit = 50, before, after, around) {
if(limit && limit > 100) {
let logs = [];
const get = async (_before, _after) => {
Expand All @@ -1002,7 +1002,7 @@ class Client extends EventEmitter {
return get(before, after);
}
const messages = await this.requestHandler.request("GET", Endpoints.CHANNEL_MESSAGES(channelID), true, {
limit: limit || 50,
limit,
before,
after,
around
Expand Down Expand Up @@ -1311,7 +1311,7 @@ class Client extends EventEmitter {
* @arg {String} [options.enableEmoticons] Whether to enable integration emoticons or not
* @returns {Promise}
*/
editGuildIntegration(guildID, integrationID, options) {
editGuildIntegration(guildID, integrationID, options) {
return this.requestHandler.request("PATCH", Endpoints.GUILD_INTEGRATION(guildID, integrationID), true, {
expire_behavior: options.expireBehavior,
expire_grace_period: options.expireGracePeriod,
Expand Down Expand Up @@ -1349,10 +1349,10 @@ class Client extends EventEmitter {
}

/**
* Returns the vanity url of the guild
* @arg {String} guildID The ID of the guild
* @returns {Promise}
*/
* Returns the vanity url of the guild
* @arg {String} guildID The ID of the guild
* @returns {Promise}
*/
getGuildVanity(guildID) {
return this.requestHandler.request("GET", Endpoints.GUILD_VANITY_URL(guildID), true);
}
Expand Down Expand Up @@ -1633,7 +1633,7 @@ class Client extends EventEmitter {
*/
editUserNote(userID, note) {
return this.requestHandler.request("PUT", Endpoints.USER_NOTE("@me", userID), true, {
note: note
note
});
}

Expand Down Expand Up @@ -1741,7 +1741,7 @@ class Client extends EventEmitter {
restricted_guilds: data.restrictedGuilds,
show_current_game: data.showCurrentGame,
status: data.status,
theme: data.theme,
theme: data.theme
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ module.exports.AuditLogActions = {
module.exports.MessageFlags = {
CROSSPOSTED: 1 << 0,
IS_CROSSPOST: 1 << 1,
SUPPRESS_EMBEDS: 1 << 2,
SUPPRESS_EMBEDS: 1 << 2
};
14 changes: 7 additions & 7 deletions lib/command/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class Command {
this.cooldownTimeouts[userID] = setTimeout(() => {
this.usersOnCooldown.delete(userID);
}, this.cooldown);
} else{
} else {
setTimeout(() => {
this.usersOnCooldown.delete(userID);
}, this.cooldown);
Expand All @@ -272,7 +272,7 @@ class Command {

if(this.hooks.preCommand) {
const response = await Promise.resolve(this.hooks.preCommand(msg, args));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand All @@ -282,7 +282,7 @@ class Command {
if(!this.permissionCheck(msg)) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, false));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand All @@ -304,7 +304,7 @@ class Command {
if(this.argsRequired) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand All @@ -318,7 +318,7 @@ class Command {
if(this.cooldown !== 0 && !this.cooldownCheck(msg)) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand All @@ -345,7 +345,7 @@ class Command {
if(this.cooldown !== 0 && !this.cooldownCheck(msg)) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, false));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand All @@ -365,7 +365,7 @@ class Command {
async executeCommand(msg, args) {
if(this.hooks.postCheck) {
const response = await Promise.resolve(this.hooks.postCheck(msg, args, true));
if (response) {
if(response) {
msg = response.msg || msg;
args = response.args || args;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/command/CommandClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CommandClient extends Client {
name: null,
owner: "an unknown user",
prefix: "@mention ",
defaultCommandOptions: {},
defaultCommandOptions: {}
}, commandOptions);
this.guildPrefixes = {};
this.commands = {};
Expand Down Expand Up @@ -127,9 +127,9 @@ class CommandClient extends Client {
}

/**
* Checks the command client for a command based on the provided message
* @arg {Message} msg The message object from the message create event
*/
* Checks the command client for a command based on the provided message
* @arg {Message} msg The message object from the message create event
*/
async onMessageCreate(msg) {
if(!this.ready) {
return;
Expand All @@ -152,7 +152,7 @@ class CommandClient extends Client {
if(!(resp instanceof Message)) {
resp = await this.createMessage(msg.channel.id, resp); // eslint-disable-line require-atomic-updates
}
if (msg.command.reactionButtons) {
if(msg.command.reactionButtons) {
msg.command.reactionButtons.forEach((button) => resp.addReaction(button.emoji));
this.activeMessages[resp.id] = {
args: args,
Expand Down