From 7638e405546394b251eeb8008a9bb35df556f3a8 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 3 Apr 2018 19:50:20 -0400 Subject: [PATCH] Updated sendMessage to sendMessage. Updated data.js to throw errors. --- src/commands/ban.js | 6 +++--- src/commands/clearWarnings.js | 6 +++--- src/commands/grantDeveloper.js | 4 ++-- src/commands/quote.js | 2 +- src/commands/warn.js | 6 +++--- src/commands/warnings.js | 2 +- src/data.js | 12 +++++++----- src/server.js | 6 +++--- src/triggers/github.js | 2 +- 9 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/commands/ban.js b/src/commands/ban.js index 21d682c..39ea2bd 100644 --- a/src/commands/ban.js +++ b/src/commands/ban.js @@ -8,14 +8,14 @@ exports.command = function (message) { message.mentions.users.map((user) => { var count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0; - message.channel.sendMessage(`${user} ${user.username}, You will now be banned from this channel.`); + message.channel.send(`${user} ${user.username}, You will now be banned from this channel.`); logger.info(`${message.author.toString()} has banned ${user.toString()} ${user} ${user.username}.`); - state.logChannel.sendMessage(`${message.author} has banned ${user} ${user.username} [${count}].`); + state.logChannel.send(`${message.author} has banned ${user} ${user.username} [${count}].`); state.bans.push(new UserBan(user.id, user.username, message.author.id, message.author.username, count)); message.guild.member(user).ban().catch(function (error) { - state.logChannel.sendMessage(`Error banning ${user} ${user.username}`); + state.logChannel.send(`Error banning ${user} ${user.username}`); logger.error(`Error banning ${user.toString()} ${user} ${user.username}.`, error); }); diff --git a/src/commands/clearWarnings.js b/src/commands/clearWarnings.js index 143eb62..2a8a683 100644 --- a/src/commands/clearWarnings.js +++ b/src/commands/clearWarnings.js @@ -9,12 +9,12 @@ exports.command = function (message) { if (count != null && count.length > 0) { count.forEach(warning => { warning.cleared = true; }); data.flushWarnings(); - message.channel.sendMessage(`${user}, your warnings have been cleared.`); + message.channel.send(`${user}, your warnings have been cleared.`); } else { - message.channel.sendMessage(`${user}, you have no warnings to clear.`); + message.channel.send(`${user}, you have no warnings to clear.`); } logger.info(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); - state.logChannel.sendMessage(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); + state.logChannel.send(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count}].`); }); }; diff --git a/src/commands/grantDeveloper.js b/src/commands/grantDeveloper.js index 7f6b66f..a7a0e61 100644 --- a/src/commands/grantDeveloper.js +++ b/src/commands/grantDeveloper.js @@ -7,10 +7,10 @@ exports.command = function (message) { if (alreadyJoined) { member.removeRole(role); - message.channel.sendMessage(`${user}'s speech has been revoked in the #development channel.`); + message.channel.send(`${user}'s speech has been revoked in the #development channel.`); } else { member.addRole(role); - message.channel.sendMessage(`${user} has been granted speech in the #development channel.`); + message.channel.send(`${user} has been granted speech in the #development channel.`); } }); } diff --git a/src/commands/quote.js b/src/commands/quote.js index 7f1c36b..88d1737 100644 --- a/src/commands/quote.js +++ b/src/commands/quote.js @@ -7,5 +7,5 @@ exports.command = function (message, reply) { replyMessage = `${message.mentions.users.map(user => `${user}`)} ${reply}`; } - message.channel.sendMessage(replyMessage); + message.channel.send(replyMessage); }; diff --git a/src/commands/warn.js b/src/commands/warn.js index de6e796..f729603 100644 --- a/src/commands/warn.js +++ b/src/commands/warn.js @@ -7,10 +7,10 @@ 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; - message.channel.sendMessage(`${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].`); - state.logChannel.sendMessage(`${message.author} has warned ${user} [${count} + 1].`); + state.logChannel.send(`${message.author} has warned ${user} [${count} + 1].`); state.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count)); data.flushWarnings(); @@ -18,7 +18,7 @@ exports.command = function (message) { state.stats.warnings += 1; if (count + 1 >= 3) { - state.logChannel.sendMessage(`.ban ${user}`); + state.logChannel.send(`.ban ${user}`); } }); }; diff --git a/src/commands/warnings.js b/src/commands/warnings.js index 3fcbb3a..512d328 100644 --- a/src/commands/warnings.js +++ b/src/commands/warnings.js @@ -3,6 +3,6 @@ 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); - message.channel.sendMessage(`${user}, you have ${warnings.length} total warnings.`); + message.channel.send(`${user}, you have ${warnings.length} total warnings.`); }); }; diff --git a/src/data.js b/src/data.js index 52fc336..6a0556c 100644 --- a/src/data.js +++ b/src/data.js @@ -5,7 +5,7 @@ const logger = require('./logging.js'); function readWarnings () { // Load the warnings file into the bans variable. fs.readFile('/data/discordWarnings.json', 'utf8', function (err, data) { - if (err) { throw err; } + if (err) { logger.error(err); throw err; } state.warnings = JSON.parse(data); logger.debug('Loaded warnings file.'); }); @@ -14,7 +14,7 @@ function readWarnings () { function readBans () { // Load the ban file into the bans variable. fs.readFile('/data/discordBans.json', 'utf8', function (err, data) { - if (err) { throw err; } + if (err) { logger.error(err); throw err; } state.bans = JSON.parse(data); logger.debug('Loaded bans file.'); }); @@ -24,7 +24,7 @@ function readCustomResponses() { // Load the responses file into the responses variable. fs.readFile('/data/responses.json', 'utf8', function (err, data) { - if (err) { throw err; } + if (err) { logger.error(err); throw err; } state.responses = JSON.parse(data); logger.debug('Loaded responses file from external source.'); }); @@ -33,16 +33,18 @@ function readCustomResponses() function flushWarnings () { var warningsJson = JSON.stringify(state.warnings, null, 4); if (!fs.existsSync('./data/')) fs.mkdirSync('data'); + fs.writeFile('/data/discordWarnings.json', warningsJson, 'utf8', function (err) { - if (err) { logger.error(err); } + if (err) { logger.error(err); throw err; } }); } function flushBans () { var bansJson = JSON.stringify(state.bans, null, 4); if (!fs.existsSync('data')) fs.mkdirSync('data'); + fs.writeFile('/data/discordBans.json', bansJson, 'utf8', function (err) { - if (err) { logger.error(err); } + if (err) { logger.error(err); throw err; } }); } diff --git a/src/server.js b/src/server.js index a841ebc..9f022e5 100644 --- a/src/server.js +++ b/src/server.js @@ -53,7 +53,7 @@ client.on('guildMemberRemove', (member) => { // Server is in UTC mode, 11:30 EST would be 03:30 UTC. schedule.scheduleJob({ hour: 3, minute: 30 }, function () { logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.ruleAccepts} users have accepted the rules, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`); - state.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.ruleAccepts} users have accepted the rules, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`); + state.logChannel.send(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${state.stats.joins} users have joined, ${state.stats.ruleAccepts} users have accepted the rules, ${state.stats.leaves} users have left, ${state.stats.warnings} warnings have been issued.`); // Clear the stats for the day. state.stats.joins = 0; @@ -68,7 +68,7 @@ client.on('message', message => { if (message.guild == null && state.responses.pmReply) { // We want to log PM attempts. logger.info(`${message.author.username} ${message.author} [PM]: ${message.content}`); - state.logChannel.sendMessage(`${message.author} [PM]: ${message.content}`); + state.logChannel.send(`${message.author} [PM]: ${message.content}`); message.reply(state.responses.pmReply); return; } @@ -101,7 +101,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) { - state.logChannel.sendMessage(`${message.author} attempted to use admin command: ${message.content}`); + state.logChannel.send(`${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; } diff --git a/src/triggers/github.js b/src/triggers/github.js index c295e5b..80387d1 100644 --- a/src/triggers/github.js +++ b/src/triggers/github.js @@ -35,7 +35,7 @@ exports.execute = function (message) { // Set path to type of comment (issues/pull) let path = response.request.uri.pathname.split('/')[3]; - message.channel.sendMessage(`Github ${map[path]}: ${url}`); + message.channel.send(`Github ${map[path]}: ${url}`); } });