Fix EsLint warnings and add some files to .gitignore (#60)

* Silence git about my local IDE files

This was copy-pasted from Citras .gitignore file.

* Fix some typos

* Prevent coercion warning

* Fix the rest of EsLinter warnings

Fixes wrong spacing, missing semicolons, unecessary RegEx escapes, unecessary undefined init and unused variables.

* Replace var with const or let
This commit is contained in:
Tobias 2019-07-22 02:56:54 +02:00 committed by Flame Sage
parent c3cc3820d4
commit 9a1a207d2c
14 changed files with 71 additions and 69 deletions

7
.gitignore vendored
View File

@ -42,3 +42,10 @@ jspm_packages
# Configuration
config/production.json
config/development.json
# Project/editor files
*.swp
.idea/
.vs/
.vscode/
CMakeLists.txt.user*

View File

@ -6,7 +6,7 @@ const UserBan = require('../models/UserBan.js');
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
exports.command = function (message) {
message.mentions.users.map((user) => {
var count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
logger.info(`${message.author.toString()} has banned ${user.toString()} ${user} ${user.username}.`);
state.logChannel.send(`${message.author} has banned ${user} ${user.username} [${count}].`);

View File

@ -5,7 +5,7 @@ const logger = require('../logging.js');
exports.roles = ['Admins', 'Moderators'];
exports.command = function (message) {
message.mentions.users.map((user) => {
var count = state.warnings.filter(x => x.id === user.id && !x.cleared);
const count = state.warnings.filter(x => x.id === user.id && !x.cleared);
if (count != null && count.length > 0) {
count.forEach(warning => { warning.cleared = true; });
data.flushWarnings();

View File

@ -20,7 +20,7 @@ const compatStrings = {
99: { "key": "99", "name": "Not Tested", "color": "black", "description": "The game has not yet been tested." }
};
async function updateDatabase() {
async function updateDatabase () {
let body;
try {
body = await request(targetServer);
@ -34,7 +34,7 @@ async function updateDatabase() {
directory: x.directory,
title: x.title,
compatibility: x.compatibility
}
};
});
state.lastGameDBUpdate = Date.now();

View File

@ -1,6 +1,6 @@
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
exports.command = function (message) {
var role = process.env.DISCORD_DEVELOPER_ROLE
const role = process.env.DISCORD_DEVELOPER_ROLE;
message.mentions.users.map((user) => {
let member = message.guild.member(user);
let alreadyJoined = member.roles.has(role);
@ -13,4 +13,4 @@ exports.command = function (message) {
message.channel.send(`${user} has been granted speech in the #development channel.`);
}
});
}
};

View File

@ -1,30 +1,26 @@
const request = require('request');
const logger = require('../logging.js');
exports.roles = ['Admins', 'Moderators', 'Developers'];
exports.command = function (message) {
let pr = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, '');
let pr = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, '');
let repo = process.env.GITHUB_REPOSITORY || "citra-emu/citra";
let url = `https://api.github.com/repos/${repo}/pulls/${pr}`;
request({ url: url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)'}}, function (error, response, body) {
let repo = process.env.GITHUB_REPOSITORY || "citra-emu/citra";
let url = `https://api.github.com/repos/${repo}/pulls/${pr}`;
request({ url: url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)' } }, function (error, response, body) {
if (!error) {
var pr = JSON.parse(body);
request({ url: pr.statuses_url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)'}}, function(error, response, body)
{
var statuses = JSON.parse(body);
const pr = JSON.parse(body);
request({ url: pr.statuses_url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)' } }, function (error, response, body) {
const statuses = JSON.parse(body);
if (statuses.length == 0) return;
if (statuses.length === 0) return;
// Travis CI will give you multiple, identical target URLs so we might as well just check the first one...
var status = statuses[0];
// Travis CI will give you multiple, identical target URLs so we might as well just check the first one...
const status = statuses[0];
status.target_url = status.target_url.substr(0, status.target_url.indexOf('?'));
message.channel.sendMessage(`${status.context}: ${status.target_url}: **${status.state}**`);
});
}
else
{
} else {
message.channel.sendMessage('No such PR.');
}
});

View File

@ -6,7 +6,7 @@ const UserWarning = require('../models/UserWarning.js');
exports.roles = ['Admins', 'Moderators'];
exports.command = function (message) {
message.mentions.users.map((user) => {
var count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
message.channel.send(`${user} You have been warned. Additional infractions may result in a ban.`);
logger.info(`${message.author.username} ${message.author} has warned ${user.username} ${user} [${count} + 1].`);

View File

@ -2,7 +2,7 @@ const state = require('../state.js');
exports.command = function (message) {
message.mentions.users.map((user) => {
var warnings = state.warnings.filter(x => x.id === user.id && !x.cleared);
const warnings = state.warnings.filter(x => x.id === user.id && !x.cleared);
message.channel.send(`${user}, you have ${warnings.length} total warnings.`);
});
};

View File

@ -2,9 +2,9 @@ const fs = require('fs');
const state = require('./state.js');
const logger = require('./logging.js');
function readWarnings() {
function readWarnings () {
// Load the warnings file into the application state.
var readFilePath = '/data/discordWarnings.json';
const readFilePath = '/data/discordWarnings.json';
fs.readFile(readFilePath, 'utf8', function (err, data) {
if (err) { throw err; }
if (data) {
@ -16,9 +16,9 @@ function readWarnings() {
});
}
function readBans() {
function readBans () {
// Load the ban file into the application state.
var readFilePath = '/data/discordBans.json';
const readFilePath = '/data/discordBans.json';
fs.readFile(readFilePath, 'utf8', function (err, data) {
if (err) { throw err; }
if (data) {
@ -30,21 +30,21 @@ function readBans() {
});
}
function readCustomResponses() {
function readCustomResponses () {
// Load the responses file into the responses variable.
state.responses = require(`./responses/${process.env.TENANT}.json`);
state.responses = require(`./responses/${process.env.TENANT}.json`);
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
}
function flushWarnings() {
var warningsJson = JSON.stringify(state.warnings, null, 4);
function flushWarnings () {
const warningsJson = JSON.stringify(state.warnings, null, 4);
fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) {
if (err) { throw err; }
});
}
function flushBans() {
var bansJson = JSON.stringify(state.bans, null, 4);
function flushBans () {
const bansJson = JSON.stringify(state.bans, null, 4);
fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) {
if (err) { throw err; }
});

View File

@ -4,7 +4,7 @@ const os = require('os');
winston.emitErrs = true;
var logger = new winston.Logger({
const logger = new winston.Logger({
level: 'debug',
transports: [
new (winston.transports.Console)()
@ -19,17 +19,17 @@ var logger = new winston.Logger({
if (process.env.LOGDNA_API_KEY) {
require('logdna');
const logLevel = process.env.LOGDNA_LEVEL || 'info';
logger.add(winston.transports.Logdna, {
level: logLevel,
app: process.env.LOGDNA_APPNAME,
index_meta: true,
key: process.env.LOGDNA_API_KEY,
ip: ip.address(),
hostname: os.hostname()
});
logger.info(`[core] Started LogDNA winston transport. Running at log level ${logLevel}.`);
logger.add(winston.transports.Logdna, {
level: logLevel,
app: process.env.LOGDNA_APPNAME,
index_meta: true,
key: process.env.LOGDNA_API_KEY,
ip: ip.address(),
hostname: os.hostname()
});
logger.info(`[core] Started LogDNA winston transport. Running at log level ${logLevel}.`);
}
module.exports = logger;

View File

@ -19,10 +19,10 @@
"( ͡° ͜ʖ ͡°)": { "reply": "lenny"},
"format": { "reply": "A full description of game formats the yuzu supports and when to use them can be found on our wiki. <https://yuzu-emu.org/wiki/overview-of-switch-game-formats/>"},
"keys": { "reply": "Most games require encryption keys to boot. You can dump them from your Switch by following this guide. <https://yuzu-emu.org/help/quickstart/#keys>"},
"game-updates": { "reply": "Installing and using game updates are a seperate process from the base game. Check out our updates tutorial on our wiki. <https://yuzu-emu.org/wiki/how-to-install-and-use-game-updates/>"},
"game-updates": { "reply": "Installing and using game updates are a separate process from the base game. Check out our updates tutorial on our wiki. <https://yuzu-emu.org/wiki/how-to-install-and-use-game-updates/>"},
"log": { "reply": "This forum topic tells you how to __get the log file__: <https://community.citra-emu.org/t/how-to-upload-the-log-file/296>"},
"pikachu": { "reply": "https://cdn.discordapp.com/attachments/512678820092968971/516372335826042901/yote.png"},
"quickstart": { "reply": "Please reference the __Quickstart Guide__ in order to dump your games, keys, and system files for use with yuzu. <https://yuzu-emu.org/help/quickstart/>"}
}
}

View File

@ -12,16 +12,16 @@ const data = require('./data.js');
state.responses = require('./responses.json');
var cachedModules = [];
var cachedTriggers = [];
var client = new discord.Client();
let cachedModules = [];
let cachedTriggers = [];
const client = new discord.Client();
let mediaUsers = new Map();
logger.info('Application startup. Configuring environment.');
process.on('unhandledRejection', (error, promise) => {
logger.error(`Unhandled promise rejection: ${error.message}.`, { meta: error });
logger.error(`Unhandled promise rejection: ${error.message}.`, { meta: error });
});
process.on('uncaughtException', error => {
@ -29,14 +29,14 @@ process.on('uncaughtException', error => {
process.exit(-1);
});
function findArray(haystack, arr) {
function findArray (haystack, arr) {
return arr.some(function (v) {
return haystack.indexOf(v) >= 0;
});
}
client.on('ready', () => {
// Initalize app channels.
// Initialize app channels.
state.logChannel = client.channels.get(process.env.DISCORD_LOG_CHANNEL);
state.guild = state.logChannel.guild;
@ -44,22 +44,22 @@ client.on('ready', () => {
});
client.on('error', (x) => {
logger.error(x)
logger.error('Restarting process.')
process.exit(1)
})
logger.error(x);
logger.error('Restarting process.');
process.exit(1);
});
client.on('warn', (x) => {
logger.warn(x)
})
logger.warn(x);
});
client.on('debug', (x) => null)
client.on('debug', (x) => null);
client.on('disconnect', () => {
logger.warn('Disconnected from Discord server.');
})
logger.warn('Disconnected from Discord server.');
});
client.on('reconnecting', () => {
logger.warn('Reconnecting...');
})
logger.warn('Reconnecting...');
});
client.on('guildMemberAdd', (member) => {
member.addRole(process.env.DISCORD_RULES_ROLE);
@ -157,7 +157,7 @@ client.on('message', message => {
try {
// Check if the command requires a warning.
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 privileges to warn.
let warnCommand = cachedModules['warn.js'];
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.

View File

@ -1,5 +1,5 @@
/* Application State */
var State = function () {
const State = function () {
this.guild = null;
this.logChannel = null;
this.warnings = [];

View File

@ -1,6 +1,6 @@
const request = require('request');
const regex = /[^\<\\]\#(\d+)/ig;
const regex = /[^<\\]#(\d+)/ig;
exports.trigger = function (message) {
return new RegExp(regex).test(message.content);
@ -33,10 +33,9 @@ exports.execute = function (message) {
let url = `https://github.com/${repo}/pull/${match[1]}`;
request(url, function (error, response, body) {
if (!error && response.statusCode === 200) {
// Set path to type of comment (issues/pull)
let path = response.request.uri.pathname.split('/')[3];
message.channel.send(`Github ${map[path]}: ${url}`);
}
});