Added linter. Corrected linter errors.

This commit is contained in:
chris062689 2017-09-29 19:38:00 -04:00
parent 5fe71a0e40
commit 5a8f645787
7 changed files with 1530 additions and 67 deletions

6
.eslintrc.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": ["eslint:recommended", "standard"],
"rules": {
"semi": [2, "always"]
}
}

View File

@ -26,7 +26,7 @@ function flushWarnings() {
var warningsJson = JSON.stringify(app.warnings, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordWarnings.json', warningsJson, 'utf8', function (err) {
if (err) return console.log(err);
if (err) { logger.error(err); }
});
}
@ -34,8 +34,8 @@ function flushBans() {
var bansJson = JSON.stringify(app.bans, null, 4);
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
fs.writeFile('./data/discordBans.json', bansJson, 'utf8', function (err) {
if (err) return console.log(err);
if (err) { logger.error(err); }
});
}
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans }
module.exports = { readWarnings: readWarnings, readBans: readBans, flushWarnings: flushWarnings, flushBans: flushBans };

View File

@ -1,14 +1,13 @@
const winston = require('winston');
const ip = require('ip');
const os = require("os");
const logdna = require('logdna');
const os = require('os');
winston.emitErrs = true;
var logger = new winston.Logger({
level: 'debug',
transports: [
new (winston.transports.Console)(),
new (winston.transports.Console)()
],
handleExceptions: true,
humanReadableUnhandledException: true,
@ -18,6 +17,7 @@ var logger = new winston.Logger({
// Setup logging for LogDNA cloud logging.
if (process.env.LOGDNA_API_KEY) {
require('logdna');
logger.add(winston.transports.Logdna, {
level: 'info',
app: 'discord-bot',
@ -26,6 +26,7 @@ if (process.env.LOGDNA_API_KEY) {
ip: ip.address(),
hostname: os.hostname()
});
logger.info('Started LogDNA winston transport.');
}

1450
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,5 +16,13 @@
"node-schedule": "^1.2.3",
"request": "^2.79.0",
"winston": "^2.3.0"
},
"devDependencies": {
"eslint": "^4.8.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
}
}

View File

@ -2,7 +2,6 @@
require('checkenv').check();
const discord = require('discord.js');
const fs = require('fs');
const path = require('path');
const schedule = require('node-schedule');
@ -24,7 +23,7 @@ function findArray(haystack, arr) {
return arr.some(function (v) {
return haystack.indexOf(v) >= 0;
});
};
}
client.on('ready', () => {
// Initalize app channels.
@ -34,11 +33,11 @@ client.on('ready', () => {
logger.info('Bot is now online and connected to server.');
});
client.on("guildMemberAdd", (member) => {
client.on('guildMemberAdd', (member) => {
app.stats.joins += 1;
});
client.on("guildMemberRemove", (member) => {
client.on('guildMemberRemove', (member) => {
app.stats.leaves += 1;
});
@ -55,7 +54,7 @@ schedule.scheduleJob({ hour: 3, minute: 30 }, function(){
});
client.on('message', message => {
if (message.author.bot && message.content.startsWith('.ban') == false) { return; }
if (message.author.bot && message.content.startsWith('.ban') === false) { return; }
if (message.guild == null && responses.pmReply) {
// We want to log PM attempts.
@ -78,7 +77,7 @@ client.on('message', message => {
if (cachedModule) {
// Check access permissions.
if (cachedModule.roles != undefined && findArray(message.member.roles.map(function(x) { return x.name; }), cachedModule.roles) == false) {
if (cachedModule.roles !== undefined && findArray(message.member.roles.map(function (x) { return x.name; }), cachedModule.roles) === false) {
app.logChannel.sendMessage(`${message.author} attempted to use admin command: ${message.content}`);
logger.info(`${message.author.username} ${message.author} attempted to use admin command: ${message.content}`);
return false;
@ -88,9 +87,9 @@ client.on('message', message => {
message.delete();
try {
if (cachedModuleType == 'Command') {
if (cachedModuleType === 'Command') {
cachedModule.command(message);
} else if (cachedModuleType == 'Quote') {
} else if (cachedModuleType === 'Quote') {
cachedModules['quote.js'].command(message, cachedModule.reply);
}
} catch (err) { logger.error(err); }
@ -98,7 +97,7 @@ client.on('message', message => {
// Warn after running command?
try {
// Check if the command requires a warning.
if (cmd != 'warn' && cachedModule.warn == true) {
if (cmd !== 'warn' && cachedModule.warn === true) {
// Access check to see if the user has privilages to warn.
let warnCommand = cachedModules['warn.js'];
if (findArray(message.member.roles.map(function (x) { return x.name; }), warnCommand.roles)) {
@ -107,15 +106,14 @@ client.on('message', message => {
}
}
} catch (err) { logger.error(err); }
} else {
// Not a valid command.
}
} else if (message.author.bot == false) {
} else if (message.author.bot === false) {
// This is a normal channel message.
cachedTriggers.forEach(function (trigger) {
if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) {
if (trigger.trigger(message) == true) {
if (trigger.roles === undefined || findArray(message.member.roles.map(function (x) { return x.name; }), trigger.roles)) {
if (trigger.trigger(message) === true) {
logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
try {
trigger.execute(message);
@ -128,9 +126,9 @@ client.on('message', message => {
// Cache all command modules.
cachedModules = [];
require("fs").readdirSync('./commands/').forEach(function(file) {
require('fs').readdirSync('./commands/').forEach(function (file) {
// Load the module if it's a script.
if (path.extname(file) == '.js') {
if (path.extname(file) === '.js') {
if (file.includes('.disabled')) {
logger.info(`Did not load disabled module: ${file}`);
} else {
@ -142,9 +140,9 @@ require("fs").readdirSync('./commands/').forEach(function(file) {
// Cache all triggers.
cachedTriggers = [];
require("fs").readdirSync('./triggers/').forEach(function(file) {
require('fs').readdirSync('./triggers/').forEach(function (file) {
// Load the trigger if it's a script.
if (path.extname(file) == '.js') {
if (path.extname(file) === '.js') {
if (file.includes('.disabled')) {
logger.info(`Did not load disabled trigger: ${file}`);
} else {