diff --git a/config.json.sample b/config.json.sample index 79cc137..043afd6 100644 --- a/config.json.sample +++ b/config.json.sample @@ -8,7 +8,8 @@ "password": "lolturtles", "channels": [ "#realitest" - ] + ], + "admin_channel": "#realitest" } }, "admins": [ "batman" ], diff --git a/modules/warning/config.json b/modules/warning/config.json new file mode 100644 index 0000000..914c1d7 --- /dev/null +++ b/modules/warning/config.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ "report", "users", "web" ], + "dbKeys": [ "warnings" ] +} diff --git a/modules/warning/pages.js b/modules/warning/pages.js new file mode 100644 index 0000000..d3bea78 --- /dev/null +++ b/modules/warning/pages.js @@ -0,0 +1,43 @@ +var _ = require('underscore')._; + +var pages = function(dbot) { + return { + '/warnings': function(req, res) { + res.render('warnings_servers', { + 'name': dbot.config.name, + 'servers': _.keys(this.warnings) + }); + }, + + '/warnings/:server': function(req, res) { + var server = req.params.server; + + if(_.has(this.warnings, server)) { + res.render('warnings_users', { + 'name': dbot.config.name, + 'users': _.keys(this.warnings[server]) + }); + } else { + res.render('error'); + } + }, + + '/warnings/:server/:user': function(req, res) { + var server = req.params.server, + user = req.params.user; + + if(_.has(this.warnings, server) && _.has(this.warnings.server, user)) { + res.render('warnings', { + 'name': dbot.config.name, + 'warnings': this.warnings[server][user] + }); + } else { + res.render('error'); + } + } + }; +}; + +exports.fetch = function(dbot) { + return pages(dbot); +}; diff --git a/modules/warning/strings.json b/modules/warning/strings.json new file mode 100644 index 0000000..c4abcab --- /dev/null +++ b/modules/warning/strings.json @@ -0,0 +1,11 @@ +{ + "no_warnings": { + "en": "No warnings found for {user}." + }, + "warning_info": { + "en": "{user} has {num} warnings. More info can be found at {url}" + }, + "warn_notify": { + "en": "Attention: {warner} has issued a warning to {warnee} for \"{reason}.\" More info can be found at {url}" + } +} diff --git a/modules/warning/warning.js b/modules/warning/warning.js new file mode 100644 index 0000000..51c48db --- /dev/null +++ b/modules/warning/warning.js @@ -0,0 +1,61 @@ +var _ = require('underscore')._; + +var warning = function(dbot) { + this.warnings = dbot.db.warnings; + + this.commands = { + '~warn': function(event) { + var warner = event.user, + server = event.server, + warnee = dbot.api.users.resolveUser(server, event.input[1]), + reason = event.input[2], + adminChannel = dbot.config.servers[server].admin_channel; + + // Store the warn + if(!_.has(this.warnings, server)) this.warnings[server] = {}; + if(!_.has(this.warnings[server], warnee)) this.warnings[server][warnee] = []; + + this.warnings[server][warnee].push({ + 'warner': warner, + 'reason': reason, + 'time': new Date().getTime() + }); + + // Notify interested parties + var notifyString = dbot.t('warn_notify', { + 'warner': warner, + 'warnee': warnee, + 'reason': reason, + 'url': dbot.api.web.getUrl('warnings/' + server + '/' + warnee) + }); + if(!_.isUndefined(adminChannel)) { + adminChannel = event.channel.name; + } + dbot.api.report.notify(server, adminChannel, notifyString); + dbot.say(server, adminChannel, notifyString); + dbot.say(server, warnee, notifyString); + }, + + '~warnings': function(event) { + var warnee = event.params[1], + server = event.server; + + if(_.has(this.warnings, server) && _.has(this.warnings[server], warnee)) { + event.reply(dbot.t('warning_info', { + 'user': warnee, + 'num': this.warnings[server][warnee].length, + 'url': dbot.api.web.getUrl('warnings/' + server + '/' + warnee) + })); + } else { + event.reply(dbot.t('no_warnings', { 'user': warnee })); + } + } + }; + + this.commands['~warn'].regex = [/~warn ([^ ]+) (.+)/, 3]; + this.commands['~warn'].access = 'moderator'; +}; + +exports.fetch = function(dbot) { + return new warning(dbot); +};