Updated sendMessage to sendMessage. Updated data.js to throw errors.

This commit is contained in:
Chris 2018-04-03 19:50:20 -04:00
parent d3422138ca
commit 7638e40554
9 changed files with 24 additions and 22 deletions

View File

@ -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);
});

View File

@ -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}].`);
});
};

View File

@ -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.`);
}
});
}

View File

@ -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);
};

View File

@ -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}`);
}
});
};

View File

@ -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.`);
});
};

View File

@ -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; }
});
}

View File

@ -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;
}

View File

@ -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}`);
}
});