Added Application stats, will output at midnight to the server and log.

This commit is contained in:
chris062689 2017-07-19 21:45:58 -04:00
parent bc22735a5c
commit 6b210b3270
5 changed files with 28 additions and 0 deletions

5
app.js
View file

@ -4,6 +4,11 @@ var Application = function() {
this.logChannel = null;
this.warnings = [];
this.bans = [];
this.stats = {
joins: 0,
leaves: 0,
warnings: 0
};
};
module.exports = new Application();

View file

@ -19,6 +19,7 @@ exports.command = function(message) {
app.logChannel.sendMessage(`Error banning ${user} ${user.username}`);
logger.error(`Error banning ${user.toString()} ${user} ${user.username}.`, error);
});
data.flushBans();
});
}

View file

@ -16,6 +16,8 @@ exports.command = function(message) {
app.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count));
data.flushWarnings();
app.stats.warnings += 1;
if (count + 1 >= 3) {
app.logChannel.sendMessage(`.ban ${user}`);
}

View file

@ -13,6 +13,7 @@
"discord.js": "^10.0.1",
"ip": "^1.1.5",
"logdna": "^1.2.3",
"node-schedule": "^1.2.3",
"request": "^2.79.0",
"winston": "^2.3.0"
}

View file

@ -29,6 +29,25 @@ client.on('ready', () => {
logger.info('Bot is now online and connected to server.');
});
client.on("guildMemberAdd", (member) => {
app.stats.joins += 1;
});
client.on("guildMemberRemove", (member) => {
app.stats.leaves += 1;
});
// Output the stats for app.stats every 24 hours.
schedule.scheduleJob({ hour: 23, minute: 59 }, function(){
logger.info(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
app.logChannel.sendMessage(`Here are today's stats for ${(new Date()).toLocaleDateString()}! ${app.stats.joins} users have joined, ${app.stats.leaves} users have left, ${app.stats.warnings} warnings have been issued.`);
// Clear the stats for the day.
app.stats.joins = 0;
app.stats.leaves = 0;
app.stats.warnings = 0;
});
client.on('message', message => {
if (message.author.bot && message.content.startsWith('.ban') == false) { return; }