mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-22 14:05:36 +01:00
Added linter. Corrected linter errors.
This commit is contained in:
parent
5fe71a0e40
commit
5a8f645787
6
.eslintrc.json
Normal file
6
.eslintrc.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": ["eslint:recommended", "standard"],
|
||||||
|
"rules": {
|
||||||
|
"semi": [2, "always"]
|
||||||
|
}
|
||||||
|
}
|
6
data.js
6
data.js
@ -26,7 +26,7 @@ function flushWarnings() {
|
|||||||
var warningsJson = JSON.stringify(app.warnings, null, 4);
|
var warningsJson = JSON.stringify(app.warnings, null, 4);
|
||||||
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
|
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
|
||||||
fs.writeFile('./data/discordWarnings.json', warningsJson, 'utf8', function (err) {
|
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);
|
var bansJson = JSON.stringify(app.bans, null, 4);
|
||||||
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
|
if (!fs.existsSync('./data/')) fs.mkdirSync('./data/');
|
||||||
fs.writeFile('./data/discordBans.json', bansJson, 'utf8', function (err) {
|
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 };
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const ip = require('ip');
|
const ip = require('ip');
|
||||||
const os = require("os");
|
const os = require('os');
|
||||||
const logdna = require('logdna');
|
|
||||||
|
|
||||||
winston.emitErrs = true;
|
winston.emitErrs = true;
|
||||||
|
|
||||||
var logger = new winston.Logger({
|
var logger = new winston.Logger({
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
transports: [
|
transports: [
|
||||||
new (winston.transports.Console)(),
|
new (winston.transports.Console)()
|
||||||
],
|
],
|
||||||
handleExceptions: true,
|
handleExceptions: true,
|
||||||
humanReadableUnhandledException: true,
|
humanReadableUnhandledException: true,
|
||||||
@ -18,6 +17,7 @@ var logger = new winston.Logger({
|
|||||||
|
|
||||||
// Setup logging for LogDNA cloud logging.
|
// Setup logging for LogDNA cloud logging.
|
||||||
if (process.env.LOGDNA_API_KEY) {
|
if (process.env.LOGDNA_API_KEY) {
|
||||||
|
require('logdna');
|
||||||
logger.add(winston.transports.Logdna, {
|
logger.add(winston.transports.Logdna, {
|
||||||
level: 'info',
|
level: 'info',
|
||||||
app: 'discord-bot',
|
app: 'discord-bot',
|
||||||
@ -26,6 +26,7 @@ if (process.env.LOGDNA_API_KEY) {
|
|||||||
ip: ip.address(),
|
ip: ip.address(),
|
||||||
hostname: os.hostname()
|
hostname: os.hostname()
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info('Started LogDNA winston transport.');
|
logger.info('Started LogDNA winston transport.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1450
package-lock.json
generated
1450
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -16,5 +16,13 @@
|
|||||||
"node-schedule": "^1.2.3",
|
"node-schedule": "^1.2.3",
|
||||||
"request": "^2.79.0",
|
"request": "^2.79.0",
|
||||||
"winston": "^2.3.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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
server.js
32
server.js
@ -2,7 +2,6 @@
|
|||||||
require('checkenv').check();
|
require('checkenv').check();
|
||||||
|
|
||||||
const discord = require('discord.js');
|
const discord = require('discord.js');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const schedule = require('node-schedule');
|
const schedule = require('node-schedule');
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ function findArray(haystack, arr) {
|
|||||||
return arr.some(function (v) {
|
return arr.some(function (v) {
|
||||||
return haystack.indexOf(v) >= 0;
|
return haystack.indexOf(v) >= 0;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
// Initalize app channels.
|
// Initalize app channels.
|
||||||
@ -34,11 +33,11 @@ client.on('ready', () => {
|
|||||||
logger.info('Bot is now online and connected to server.');
|
logger.info('Bot is now online and connected to server.');
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("guildMemberAdd", (member) => {
|
client.on('guildMemberAdd', (member) => {
|
||||||
app.stats.joins += 1;
|
app.stats.joins += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("guildMemberRemove", (member) => {
|
client.on('guildMemberRemove', (member) => {
|
||||||
app.stats.leaves += 1;
|
app.stats.leaves += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ schedule.scheduleJob({ hour: 3, minute: 30 }, function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('message', message => {
|
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) {
|
if (message.guild == null && responses.pmReply) {
|
||||||
// We want to log PM attempts.
|
// We want to log PM attempts.
|
||||||
@ -78,7 +77,7 @@ client.on('message', message => {
|
|||||||
|
|
||||||
if (cachedModule) {
|
if (cachedModule) {
|
||||||
// Check access permissions.
|
// 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}`);
|
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}`);
|
logger.info(`${message.author.username} ${message.author} attempted to use admin command: ${message.content}`);
|
||||||
return false;
|
return false;
|
||||||
@ -88,9 +87,9 @@ client.on('message', message => {
|
|||||||
message.delete();
|
message.delete();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cachedModuleType == 'Command') {
|
if (cachedModuleType === 'Command') {
|
||||||
cachedModule.command(message);
|
cachedModule.command(message);
|
||||||
} else if (cachedModuleType == 'Quote') {
|
} else if (cachedModuleType === 'Quote') {
|
||||||
cachedModules['quote.js'].command(message, cachedModule.reply);
|
cachedModules['quote.js'].command(message, cachedModule.reply);
|
||||||
}
|
}
|
||||||
} catch (err) { logger.error(err); }
|
} catch (err) { logger.error(err); }
|
||||||
@ -98,7 +97,7 @@ client.on('message', message => {
|
|||||||
// Warn after running command?
|
// Warn after running command?
|
||||||
try {
|
try {
|
||||||
// Check if the command requires a warning.
|
// 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.
|
// Access check to see if the user has privilages to warn.
|
||||||
let warnCommand = cachedModules['warn.js'];
|
let warnCommand = cachedModules['warn.js'];
|
||||||
if (findArray(message.member.roles.map(function (x) { return x.name; }), warnCommand.roles)) {
|
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); }
|
} catch (err) { logger.error(err); }
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Not a valid command.
|
// Not a valid command.
|
||||||
}
|
}
|
||||||
} else if (message.author.bot == false) {
|
} else if (message.author.bot === false) {
|
||||||
// This is a normal channel message.
|
// This is a normal channel message.
|
||||||
cachedTriggers.forEach(function (trigger) {
|
cachedTriggers.forEach(function (trigger) {
|
||||||
if (trigger.roles == undefined || findArray(message.member.roles.map(function(x) { return x.name; }), trigger.roles)) {
|
if (trigger.roles === undefined || findArray(message.member.roles.map(function (x) { return x.name; }), trigger.roles)) {
|
||||||
if (trigger.trigger(message) == true) {
|
if (trigger.trigger(message) === true) {
|
||||||
logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
|
logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
|
||||||
try {
|
try {
|
||||||
trigger.execute(message);
|
trigger.execute(message);
|
||||||
@ -128,9 +126,9 @@ client.on('message', message => {
|
|||||||
|
|
||||||
// Cache all command modules.
|
// Cache all command modules.
|
||||||
cachedModules = [];
|
cachedModules = [];
|
||||||
require("fs").readdirSync('./commands/').forEach(function(file) {
|
require('fs').readdirSync('./commands/').forEach(function (file) {
|
||||||
// Load the module if it's a script.
|
// Load the module if it's a script.
|
||||||
if (path.extname(file) == '.js') {
|
if (path.extname(file) === '.js') {
|
||||||
if (file.includes('.disabled')) {
|
if (file.includes('.disabled')) {
|
||||||
logger.info(`Did not load disabled module: ${file}`);
|
logger.info(`Did not load disabled module: ${file}`);
|
||||||
} else {
|
} else {
|
||||||
@ -142,9 +140,9 @@ require("fs").readdirSync('./commands/').forEach(function(file) {
|
|||||||
|
|
||||||
// Cache all triggers.
|
// Cache all triggers.
|
||||||
cachedTriggers = [];
|
cachedTriggers = [];
|
||||||
require("fs").readdirSync('./triggers/').forEach(function(file) {
|
require('fs').readdirSync('./triggers/').forEach(function (file) {
|
||||||
// Load the trigger if it's a script.
|
// Load the trigger if it's a script.
|
||||||
if (path.extname(file) == '.js') {
|
if (path.extname(file) === '.js') {
|
||||||
if (file.includes('.disabled')) {
|
if (file.includes('.disabled')) {
|
||||||
logger.info(`Did not load disabled trigger: ${file}`);
|
logger.info(`Did not load disabled trigger: ${file}`);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user