mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-25 22:05:39 +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"]
|
||||||
|
}
|
||||||
|
}
|
20
app.js
20
app.js
@ -1,14 +1,14 @@
|
|||||||
/* Application State */
|
/* Application State */
|
||||||
var Application = function() {
|
var Application = function () {
|
||||||
this.guild = null;
|
this.guild = null;
|
||||||
this.logChannel = null;
|
this.logChannel = null;
|
||||||
this.warnings = [];
|
this.warnings = [];
|
||||||
this.bans = [];
|
this.bans = [];
|
||||||
this.stats = {
|
this.stats = {
|
||||||
joins: 0,
|
joins: 0,
|
||||||
leaves: 0,
|
leaves: 0,
|
||||||
warnings: 0
|
warnings: 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = new Application();
|
module.exports = new Application();
|
||||||
|
14
data.js
14
data.js
@ -2,7 +2,7 @@ var fs = require('fs');
|
|||||||
var app = require('./app.js');
|
var app = require('./app.js');
|
||||||
var logger = require('./logging.js');
|
var logger = require('./logging.js');
|
||||||
|
|
||||||
function readWarnings() {
|
function readWarnings () {
|
||||||
// Load the warnings file into the bans variable.
|
// Load the warnings file into the bans variable.
|
||||||
fs.readFile('./data/discordWarnings.json', 'utf8', function (err, data) {
|
fs.readFile('./data/discordWarnings.json', 'utf8', function (err, data) {
|
||||||
if (err && err.code === 'ENOENT') { return; }
|
if (err && err.code === 'ENOENT') { return; }
|
||||||
@ -12,7 +12,7 @@ function readWarnings() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBans() {
|
function readBans () {
|
||||||
// Load the ban file into the bans variable.
|
// Load the ban file into the bans variable.
|
||||||
fs.readFile('./data/discordBans.json', 'utf8', function (err, data) {
|
fs.readFile('./data/discordBans.json', 'utf8', function (err, data) {
|
||||||
if (err && err.code === 'ENOENT') { return; }
|
if (err && err.code === 'ENOENT') { return; }
|
||||||
@ -22,20 +22,20 @@ function readBans() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function flushWarnings() {
|
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); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function flushBans() {
|
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 };
|
||||||
|
39
logging.js
39
logging.js
@ -1,32 +1,33 @@
|
|||||||
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,
|
||||||
exitOnError: false,
|
exitOnError: false,
|
||||||
meta: true
|
meta: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup logging for LogDNA cloud logging.
|
// Setup logging for LogDNA cloud logging.
|
||||||
if (process.env.LOGDNA_API_KEY) {
|
if (process.env.LOGDNA_API_KEY) {
|
||||||
logger.add(winston.transports.Logdna, {
|
require('logdna');
|
||||||
level: 'info',
|
logger.add(winston.transports.Logdna, {
|
||||||
app: 'discord-bot',
|
level: 'info',
|
||||||
index_meta: true,
|
app: 'discord-bot',
|
||||||
key: process.env.LOGDNA_API_KEY,
|
index_meta: true,
|
||||||
ip: ip.address(),
|
key: process.env.LOGDNA_API_KEY,
|
||||||
hostname: os.hostname()
|
ip: ip.address(),
|
||||||
});
|
hostname: os.hostname()
|
||||||
logger.info('Started LogDNA winston transport.');
|
});
|
||||||
|
|
||||||
|
logger.info('Started LogDNA winston transport.');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = logger;
|
module.exports = logger;
|
||||||
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
58
server.js
58
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');
|
||||||
|
|
||||||
@ -16,15 +15,15 @@ var cachedModules = [];
|
|||||||
var cachedTriggers = [];
|
var cachedTriggers = [];
|
||||||
var client = new discord.Client();
|
var client = new discord.Client();
|
||||||
|
|
||||||
process.on('unhandledRejection', function onError(err) {
|
process.on('unhandledRejection', function onError (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
function findArray(haystack, arr) {
|
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,17 +33,17 @@ 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;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Output the stats for app.stats every 24 hours.
|
// Output the stats for app.stats every 24 hours.
|
||||||
// Server is in UTC mode, 11:30 EST would be 03:30 UTC.
|
// Server is in UTC mode, 11:30 EST would be 03:30 UTC.
|
||||||
schedule.scheduleJob({ hour: 3, minute: 30 }, function(){
|
schedule.scheduleJob({ hour: 3, minute: 30 }, function () {
|
||||||
logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
|
logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
|
||||||
app.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
|
app.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
|
||||||
|
|
||||||
@ -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,39 +97,38 @@ 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)) {
|
||||||
// They are allowed to warn because they are in warn's roles.
|
// They are allowed to warn because they are in warn's roles.
|
||||||
warnCommand.command(message);
|
warnCommand.command(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);
|
||||||
} catch (err) { logger.error(err); }
|
} catch (err) { logger.error(err); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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