mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-22 08:45:41 +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"]
|
||||
}
|
||||
}
|
2
app.js
2
app.js
@ -1,5 +1,5 @@
|
||||
/* Application State */
|
||||
var Application = function() {
|
||||
var Application = function () {
|
||||
this.guild = null;
|
||||
this.logChannel = null;
|
||||
this.warnings = [];
|
||||
|
14
data.js
14
data.js
@ -2,7 +2,7 @@ var fs = require('fs');
|
||||
var app = require('./app.js');
|
||||
var logger = require('./logging.js');
|
||||
|
||||
function readWarnings() {
|
||||
function readWarnings () {
|
||||
// Load the warnings file into the bans variable.
|
||||
fs.readFile('./data/discordWarnings.json', 'utf8', function (err, data) {
|
||||
if (err && err.code === 'ENOENT') { return; }
|
||||
@ -12,7 +12,7 @@ function readWarnings() {
|
||||
});
|
||||
}
|
||||
|
||||
function readBans() {
|
||||
function readBans () {
|
||||
// Load the ban file into the bans variable.
|
||||
fs.readFile('./data/discordBans.json', 'utf8', function (err, data) {
|
||||
if (err && err.code === 'ENOENT') { return; }
|
||||
@ -22,20 +22,20 @@ function readBans() {
|
||||
});
|
||||
}
|
||||
|
||||
function flushWarnings() {
|
||||
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); }
|
||||
});
|
||||
}
|
||||
|
||||
function flushBans() {
|
||||
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 };
|
||||
|
@ -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
1450
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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"
|
||||
}
|
||||
}
|
||||
|
42
server.js
42
server.js
@ -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');
|
||||
|
||||
@ -16,15 +15,15 @@ var cachedModules = [];
|
||||
var cachedTriggers = [];
|
||||
var client = new discord.Client();
|
||||
|
||||
process.on('unhandledRejection', function onError(err) {
|
||||
process.on('unhandledRejection', function onError (err) {
|
||||
logger.error(err);
|
||||
});
|
||||
|
||||
function findArray(haystack, arr) {
|
||||
function findArray (haystack, arr) {
|
||||
return arr.some(function (v) {
|
||||
return haystack.indexOf(v) >= 0;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
client.on('ready', () => {
|
||||
// Initalize app channels.
|
||||
@ -34,17 +33,17 @@ 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;
|
||||
});
|
||||
|
||||
// Output the stats for app.stats every 24 hours.
|
||||
// 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.`);
|
||||
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 => {
|
||||
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,24 +97,23 @@ 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)) {
|
||||
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.
|
||||
warnCommand.command(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) {
|
||||
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) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user