diff --git a/.gitignore b/.gitignore
index 7cd615f..f1be72b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,3 +42,10 @@ jspm_packages
# Configuration
config/production.json
config/development.json
+
+# Project/editor files
+*.swp
+.idea/
+.vs/
+.vscode/
+CMakeLists.txt.user*
diff --git a/src/commands/ban.js b/src/commands/ban.js
index 2267ba3..a0a14d4 100644
--- a/src/commands/ban.js
+++ b/src/commands/ban.js
@@ -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}].`);
diff --git a/src/commands/clearWarnings.js b/src/commands/clearWarnings.js
index 815b9a4..1e4d995 100644
--- a/src/commands/clearWarnings.js
+++ b/src/commands/clearWarnings.js
@@ -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();
diff --git a/src/commands/game.js b/src/commands/game.js
index 80d4bd6..2f7ec0c 100644
--- a/src/commands/game.js
+++ b/src/commands/game.js
@@ -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();
diff --git a/src/commands/grantDeveloper.js b/src/commands/grantDeveloper.js
index e1479ee..28dd459 100644
--- a/src/commands/grantDeveloper.js
+++ b/src/commands/grantDeveloper.js
@@ -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.`);
}
});
-}
+};
diff --git a/src/commands/status.js b/src/commands/status.js
index 95818fd..1f6f5c6 100644
--- a/src/commands/status.js
+++ b/src/commands/status.js
@@ -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.');
}
});
diff --git a/src/commands/warn.js b/src/commands/warn.js
index 8b1ad7b..7702804 100644
--- a/src/commands/warn.js
+++ b/src/commands/warn.js
@@ -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].`);
diff --git a/src/commands/warnings.js b/src/commands/warnings.js
index 512d328..22292dc 100644
--- a/src/commands/warnings.js
+++ b/src/commands/warnings.js
@@ -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.`);
});
};
diff --git a/src/data.js b/src/data.js
index 4e4af0b..f57b153 100644
--- a/src/data.js
+++ b/src/data.js
@@ -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; }
});
diff --git a/src/logging.js b/src/logging.js
index 43b0b42..33387c6 100644
--- a/src/logging.js
+++ b/src/logging.js
@@ -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;
diff --git a/src/responses/yuzu.json b/src/responses/yuzu.json
index 99cce5f..a6a1f02 100644
--- a/src/responses/yuzu.json
+++ b/src/responses/yuzu.json
@@ -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. "},
"keys": { "reply": "Most games require encryption keys to boot. You can dump them from your Switch by following this guide. "},
- "game-updates": { "reply": "Installing and using game updates are a seperate process from the base game. Check out our updates tutorial on our wiki. "},
+ "game-updates": { "reply": "Installing and using game updates are a separate process from the base game. Check out our updates tutorial on our wiki. "},
"log": { "reply": "This forum topic tells you how to __get the log file__: "},
"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. "}
}
}
-
+
diff --git a/src/server.js b/src/server.js
index 6939228..4485bb7 100644
--- a/src/server.js
+++ b/src/server.js
@@ -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.
diff --git a/src/state.js b/src/state.js
index fb057f6..4a337a2 100644
--- a/src/state.js
+++ b/src/state.js
@@ -1,5 +1,5 @@
/* Application State */
-var State = function () {
+const State = function () {
this.guild = null;
this.logChannel = null;
this.warnings = [];
diff --git a/src/triggers/github.js b/src/triggers/github.js
index 9db019c..8c46989 100644
--- a/src/triggers/github.js
+++ b/src/triggers/github.js
@@ -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}`);
}
});