mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-22 04:45:41 +01:00
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:
parent
c3cc3820d4
commit
9a1a207d2c
7
.gitignore
vendored
7
.gitignore
vendored
@ -42,3 +42,10 @@ jspm_packages
|
|||||||
# Configuration
|
# Configuration
|
||||||
config/production.json
|
config/production.json
|
||||||
config/development.json
|
config/development.json
|
||||||
|
|
||||||
|
# Project/editor files
|
||||||
|
*.swp
|
||||||
|
.idea/
|
||||||
|
.vs/
|
||||||
|
.vscode/
|
||||||
|
CMakeLists.txt.user*
|
||||||
|
@ -6,7 +6,7 @@ const UserBan = require('../models/UserBan.js');
|
|||||||
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
|
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
|
||||||
exports.command = function (message) {
|
exports.command = function (message) {
|
||||||
message.mentions.users.map((user) => {
|
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}.`);
|
logger.info(`${message.author.toString()} has banned ${user.toString()} ${user} ${user.username}.`);
|
||||||
state.logChannel.send(`${message.author} has banned ${user} ${user.username} [${count}].`);
|
state.logChannel.send(`${message.author} has banned ${user} ${user.username} [${count}].`);
|
||||||
|
@ -5,7 +5,7 @@ const logger = require('../logging.js');
|
|||||||
exports.roles = ['Admins', 'Moderators'];
|
exports.roles = ['Admins', 'Moderators'];
|
||||||
exports.command = function (message) {
|
exports.command = function (message) {
|
||||||
message.mentions.users.map((user) => {
|
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) {
|
if (count != null && count.length > 0) {
|
||||||
count.forEach(warning => { warning.cleared = true; });
|
count.forEach(warning => { warning.cleared = true; });
|
||||||
data.flushWarnings();
|
data.flushWarnings();
|
||||||
|
@ -20,7 +20,7 @@ const compatStrings = {
|
|||||||
99: { "key": "99", "name": "Not Tested", "color": "black", "description": "The game has not yet been tested." }
|
99: { "key": "99", "name": "Not Tested", "color": "black", "description": "The game has not yet been tested." }
|
||||||
};
|
};
|
||||||
|
|
||||||
async function updateDatabase() {
|
async function updateDatabase () {
|
||||||
let body;
|
let body;
|
||||||
try {
|
try {
|
||||||
body = await request(targetServer);
|
body = await request(targetServer);
|
||||||
@ -34,7 +34,7 @@ async function updateDatabase() {
|
|||||||
directory: x.directory,
|
directory: x.directory,
|
||||||
title: x.title,
|
title: x.title,
|
||||||
compatibility: x.compatibility
|
compatibility: x.compatibility
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
state.lastGameDBUpdate = Date.now();
|
state.lastGameDBUpdate = Date.now();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
|
exports.roles = ['Admins', 'Moderators', 'CitraBot'];
|
||||||
exports.command = function (message) {
|
exports.command = function (message) {
|
||||||
var role = process.env.DISCORD_DEVELOPER_ROLE
|
const role = process.env.DISCORD_DEVELOPER_ROLE;
|
||||||
message.mentions.users.map((user) => {
|
message.mentions.users.map((user) => {
|
||||||
let member = message.guild.member(user);
|
let member = message.guild.member(user);
|
||||||
let alreadyJoined = member.roles.has(role);
|
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.`);
|
message.channel.send(`${user} has been granted speech in the #development channel.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
@ -1,30 +1,26 @@
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
const logger = require('../logging.js');
|
|
||||||
|
|
||||||
exports.roles = ['Admins', 'Moderators', 'Developers'];
|
exports.roles = ['Admins', 'Moderators', 'Developers'];
|
||||||
exports.command = function (message) {
|
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 repo = process.env.GITHUB_REPOSITORY || "citra-emu/citra";
|
||||||
let url = `https://api.github.com/repos/${repo}/pulls/${pr}`;
|
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) {
|
request({ url: url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)' } }, function (error, response, body) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
var pr = 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)
|
request({ url: pr.statuses_url, headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)' } }, function (error, response, body) {
|
||||||
{
|
const statuses = JSON.parse(body);
|
||||||
var 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...
|
// Travis CI will give you multiple, identical target URLs so we might as well just check the first one...
|
||||||
var status = statuses[0];
|
const status = statuses[0];
|
||||||
status.target_url = status.target_url.substr(0, status.target_url.indexOf('?'));
|
status.target_url = status.target_url.substr(0, status.target_url.indexOf('?'));
|
||||||
message.channel.sendMessage(`${status.context}: ${status.target_url}: **${status.state}**`);
|
message.channel.sendMessage(`${status.context}: ${status.target_url}: **${status.state}**`);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
message.channel.sendMessage('No such PR.');
|
message.channel.sendMessage('No such PR.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ const UserWarning = require('../models/UserWarning.js');
|
|||||||
exports.roles = ['Admins', 'Moderators'];
|
exports.roles = ['Admins', 'Moderators'];
|
||||||
exports.command = function (message) {
|
exports.command = function (message) {
|
||||||
message.mentions.users.map((user) => {
|
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.`);
|
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].`);
|
logger.info(`${message.author.username} ${message.author} has warned ${user.username} ${user} [${count} + 1].`);
|
||||||
|
@ -2,7 +2,7 @@ const state = require('../state.js');
|
|||||||
|
|
||||||
exports.command = function (message) {
|
exports.command = function (message) {
|
||||||
message.mentions.users.map((user) => {
|
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.`);
|
message.channel.send(`${user}, you have ${warnings.length} total warnings.`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
20
src/data.js
20
src/data.js
@ -2,9 +2,9 @@ const fs = require('fs');
|
|||||||
const state = require('./state.js');
|
const state = require('./state.js');
|
||||||
const logger = require('./logging.js');
|
const logger = require('./logging.js');
|
||||||
|
|
||||||
function readWarnings() {
|
function readWarnings () {
|
||||||
// Load the warnings file into the application state.
|
// 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) {
|
fs.readFile(readFilePath, 'utf8', function (err, data) {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -16,9 +16,9 @@ function readWarnings() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBans() {
|
function readBans () {
|
||||||
// Load the ban file into the application state.
|
// 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) {
|
fs.readFile(readFilePath, 'utf8', function (err, data) {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -30,21 +30,21 @@ function readBans() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readCustomResponses() {
|
function readCustomResponses () {
|
||||||
// Load the responses file into the responses variable.
|
// 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.`);
|
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function flushWarnings() {
|
function flushWarnings () {
|
||||||
var warningsJson = JSON.stringify(state.warnings, null, 4);
|
const warningsJson = JSON.stringify(state.warnings, null, 4);
|
||||||
fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) {
|
fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function flushBans() {
|
function flushBans () {
|
||||||
var bansJson = JSON.stringify(state.bans, null, 4);
|
const bansJson = JSON.stringify(state.bans, null, 4);
|
||||||
fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) {
|
fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ const os = require('os');
|
|||||||
|
|
||||||
winston.emitErrs = true;
|
winston.emitErrs = true;
|
||||||
|
|
||||||
var logger = new winston.Logger({
|
const logger = new winston.Logger({
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
transports: [
|
transports: [
|
||||||
new (winston.transports.Console)()
|
new (winston.transports.Console)()
|
||||||
@ -19,17 +19,17 @@ var logger = new winston.Logger({
|
|||||||
if (process.env.LOGDNA_API_KEY) {
|
if (process.env.LOGDNA_API_KEY) {
|
||||||
require('logdna');
|
require('logdna');
|
||||||
const logLevel = process.env.LOGDNA_LEVEL || 'info';
|
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;
|
module.exports = logger;
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
"( ͡° ͜ʖ ͡°)": { "reply": "lenny"},
|
"( ͡° ͜ʖ ͡°)": { "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/>"},
|
"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>"},
|
"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>"},
|
"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"},
|
"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/>"}
|
"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/>"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,16 +12,16 @@ const data = require('./data.js');
|
|||||||
|
|
||||||
state.responses = require('./responses.json');
|
state.responses = require('./responses.json');
|
||||||
|
|
||||||
var cachedModules = [];
|
let cachedModules = [];
|
||||||
var cachedTriggers = [];
|
let cachedTriggers = [];
|
||||||
var client = new discord.Client();
|
const client = new discord.Client();
|
||||||
|
|
||||||
let mediaUsers = new Map();
|
let mediaUsers = new Map();
|
||||||
|
|
||||||
logger.info('Application startup. Configuring environment.');
|
logger.info('Application startup. Configuring environment.');
|
||||||
|
|
||||||
process.on('unhandledRejection', (error, promise) => {
|
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 => {
|
process.on('uncaughtException', error => {
|
||||||
@ -29,14 +29,14 @@ process.on('uncaughtException', error => {
|
|||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
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.
|
// Initialize app channels.
|
||||||
state.logChannel = client.channels.get(process.env.DISCORD_LOG_CHANNEL);
|
state.logChannel = client.channels.get(process.env.DISCORD_LOG_CHANNEL);
|
||||||
state.guild = state.logChannel.guild;
|
state.guild = state.logChannel.guild;
|
||||||
|
|
||||||
@ -44,22 +44,22 @@ client.on('ready', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('error', (x) => {
|
client.on('error', (x) => {
|
||||||
logger.error(x)
|
logger.error(x);
|
||||||
logger.error('Restarting process.')
|
logger.error('Restarting process.');
|
||||||
process.exit(1)
|
process.exit(1);
|
||||||
})
|
});
|
||||||
client.on('warn', (x) => {
|
client.on('warn', (x) => {
|
||||||
logger.warn(x)
|
logger.warn(x);
|
||||||
})
|
});
|
||||||
|
|
||||||
client.on('debug', (x) => null)
|
client.on('debug', (x) => null);
|
||||||
|
|
||||||
client.on('disconnect', () => {
|
client.on('disconnect', () => {
|
||||||
logger.warn('Disconnected from Discord server.');
|
logger.warn('Disconnected from Discord server.');
|
||||||
})
|
});
|
||||||
client.on('reconnecting', () => {
|
client.on('reconnecting', () => {
|
||||||
logger.warn('Reconnecting...');
|
logger.warn('Reconnecting...');
|
||||||
})
|
});
|
||||||
|
|
||||||
client.on('guildMemberAdd', (member) => {
|
client.on('guildMemberAdd', (member) => {
|
||||||
member.addRole(process.env.DISCORD_RULES_ROLE);
|
member.addRole(process.env.DISCORD_RULES_ROLE);
|
||||||
@ -157,7 +157,7 @@ client.on('message', message => {
|
|||||||
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 privileges 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.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Application State */
|
/* Application State */
|
||||||
var State = function () {
|
const State = function () {
|
||||||
this.guild = null;
|
this.guild = null;
|
||||||
this.logChannel = null;
|
this.logChannel = null;
|
||||||
this.warnings = [];
|
this.warnings = [];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
|
||||||
const regex = /[^\<\\]\#(\d+)/ig;
|
const regex = /[^<\\]#(\d+)/ig;
|
||||||
|
|
||||||
exports.trigger = function (message) {
|
exports.trigger = function (message) {
|
||||||
return new RegExp(regex).test(message.content);
|
return new RegExp(regex).test(message.content);
|
||||||
@ -33,10 +33,9 @@ exports.execute = function (message) {
|
|||||||
let url = `https://github.com/${repo}/pull/${match[1]}`;
|
let url = `https://github.com/${repo}/pull/${match[1]}`;
|
||||||
request(url, function (error, response, body) {
|
request(url, function (error, response, body) {
|
||||||
if (!error && response.statusCode === 200) {
|
if (!error && response.statusCode === 200) {
|
||||||
|
|
||||||
// Set path to type of comment (issues/pull)
|
// Set path to type of comment (issues/pull)
|
||||||
let path = response.request.uri.pathname.split('/')[3];
|
let path = response.request.uri.pathname.split('/')[3];
|
||||||
|
|
||||||
message.channel.send(`Github ${map[path]}: ${url}`);
|
message.channel.send(`Github ${map[path]}: ${url}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user