Added info command. Updated warnings to include silent warnings. Removed references to state.

This commit is contained in:
Chris 2019-07-21 21:45:45 -04:00
parent 9a1a207d2c
commit 91575b9029
4 changed files with 38 additions and 35 deletions

23
src/commands/info.js Normal file
View File

@ -0,0 +1,23 @@
const state = require('../state.js');
exports.roles = ['Admins', 'Moderators'];
function formatWarnings(warnings) {
return warnings.map(x => `[${x.date}] ${x.warnedByUsername} warned ${x.username} [${x.priorWarnings} + 1]. ${x.silent ? '(silent)' : ''} ${x.cleared ? '(cleared)' : ''}`)
}
function formatBans(bans) {
return bans.map(x => `[${x.date}] ${x.warnedByUsername} banned ${x.username} [${x.priorWarnings} + 1].`)
}
exports.command = function (message) {
message.mentions.users.map((user) => {
const totalWarnings = state.warnings.filter(x => x.id === user.id && x.cleared == false).length;
let warns = state.warnings.filter(x => x.id == user.id)
let bans = state.bans.filter(x => x.id == user.id)
const warnsString = `Warns:\`\`\`${formatWarnings(warns).join('\n')}\`\`\``
const bansString = `Bans:\`\`\`${formatBans(bans).join('\n')}\`\`\``
message.channel.send(`\`${user.username} (${totalWarnings}) information:\`${warns.length != 0 ? warnsString : ''}${bans.length != 0 ? bansString : ''}`)
});
}

View File

@ -5,20 +5,19 @@ const UserWarning = require('../models/UserWarning.js');
exports.roles = ['Admins', 'Moderators'];
exports.command = function (message) {
const silent = message.content.includes('silent')
message.mentions.users.map((user) => {
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.`);
if (silent == false) {
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.send(`${message.author} has warned ${user} [${count} + 1].`);
state.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count));
state.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count, silent));
data.flushWarnings();
state.stats.warnings += 1;
if (count + 1 >= 3) {
message.channel.send(`.ban ${user}`);
}
});
};

View File

@ -1,11 +1,12 @@
class UserWarning {
constructor (id, username, warnedBy, warnedByUsername, priorWarnings) {
this.id = id;
this.username = username;
this.date = new Date();
this.warnedBy = warnedBy;
this.warnedByUsername = warnedByUsername;
this.priorWarnings = priorWarnings;
constructor (id, username, warnedBy, warnedByUsername, priorWarnings, silent) {
this.id = id
this.username = username
this.date = new Date()
this.warnedBy = warnedBy
this.warnedByUsername = warnedByUsername
this.priorWarnings = priorWarnings
this.silent = silent
}
}

View File

@ -63,24 +63,6 @@ client.on('reconnecting', () => {
client.on('guildMemberAdd', (member) => {
member.addRole(process.env.DISCORD_RULES_ROLE);
state.stats.joins += 1;
});
client.on('guildMemberRemove', (member) => {
state.stats.leaves += 1;
});
// Output the stats for state.stats every 24 hours.
// 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.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;
state.stats.ruleAccepts = 0;
state.stats.leaves = 0;
state.stats.warnings = 0;
});
client.on('message', message => {
@ -116,8 +98,6 @@ client.on('message', message => {
if (message.content.toLowerCase().includes(process.env.DISCORD_RULES_TRIGGER)) {
// We want to remove the 'Unauthorized' role from them once they agree to the rules.
logger.verbose(`${message.author.username} ${message.author} has accepted the rules, removing role ${process.env.DISCORD_RULES_ROLE}.`);
state.stats.ruleAccepts += 1;
message.member.removeRole(process.env.DISCORD_RULES_ROLE, 'Accepted the rules.');
}