From 91575b9029c96728fb82f15ab3afa3472dba9a3b Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 21 Jul 2019 21:45:45 -0400 Subject: [PATCH] Added info command. Updated warnings to include silent warnings. Removed references to state. --- src/commands/info.js | 23 +++++++++++++++++++++++ src/commands/warn.js | 15 +++++++-------- src/models/UserWarning.js | 15 ++++++++------- src/server.js | 20 -------------------- 4 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 src/commands/info.js diff --git a/src/commands/info.js b/src/commands/info.js new file mode 100644 index 0000000..3642e1a --- /dev/null +++ b/src/commands/info.js @@ -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 : ''}`) + }); +} diff --git a/src/commands/warn.js b/src/commands/warn.js index 7702804..af3127e 100644 --- a/src/commands/warn.js +++ b/src/commands/warn.js @@ -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}`); - } }); }; diff --git a/src/models/UserWarning.js b/src/models/UserWarning.js index 81675ee..aeb5236 100644 --- a/src/models/UserWarning.js +++ b/src/models/UserWarning.js @@ -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 } } diff --git a/src/server.js b/src/server.js index 4485bb7..dc2deb9 100644 --- a/src/server.js +++ b/src/server.js @@ -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.'); }