initial support for warnings without web component [#506]

This commit is contained in:
reality 2013-06-19 00:06:52 +00:00
parent 051ea2ca28
commit 7d79d2330f
5 changed files with 121 additions and 1 deletions

View File

@ -8,7 +8,8 @@
"password": "lolturtles",
"channels": [
"#realitest"
]
],
"admin_channel": "#realitest"
}
},
"admins": [ "batman" ],

View File

@ -0,0 +1,4 @@
{
"dependencies": [ "report", "users", "web" ],
"dbKeys": [ "warnings" ]
}

43
modules/warning/pages.js Normal file
View File

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

View File

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

View File

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