2013-06-19 02:06:52 +02:00
|
|
|
var _ = require('underscore')._;
|
2013-06-23 13:37:01 +02:00
|
|
|
uuid = require('node-uuid');
|
2013-06-19 02:06:52 +02:00
|
|
|
|
|
|
|
var warning = function(dbot) {
|
2014-06-26 23:50:33 +02:00
|
|
|
this.api = {
|
|
|
|
'warn': function(server, warner, user, reason, channel, callback) {
|
|
|
|
var adminChannel = dbot.config.servers[server].admin_channel || channel.name;
|
|
|
|
|
2014-09-04 15:43:53 +02:00
|
|
|
dbot.api.users.resolveUser(server, user, function(err, warnee) {
|
2013-06-23 13:37:01 +02:00
|
|
|
if(warnee) {
|
|
|
|
var id = uuid.v4();
|
|
|
|
this.db.save('warnings', id, {
|
|
|
|
'id': id,
|
2014-06-26 23:50:33 +02:00
|
|
|
'server': server,
|
2013-06-23 13:37:01 +02:00
|
|
|
'warnee': warnee.id,
|
|
|
|
'warner': warner.id,
|
|
|
|
'reason': reason,
|
|
|
|
'time': new Date().getTime()
|
|
|
|
}, function(err) {
|
|
|
|
var notifyString = dbot.t('warn_notify', {
|
|
|
|
'warner': warner.primaryNick,
|
|
|
|
'warnee': warnee.primaryNick,
|
|
|
|
'reason': reason,
|
|
|
|
'url': dbot.api.web.getUrl('warning/' + server + '/'
|
|
|
|
+ warnee.primaryNick)
|
|
|
|
});
|
2013-08-28 19:35:11 +02:00
|
|
|
|
2014-06-26 23:50:33 +02:00
|
|
|
dbot.api.report.notify('warn', server, warner, adminChannel, notifyString);
|
2013-06-23 13:37:01 +02:00
|
|
|
dbot.say(server, adminChannel, notifyString);
|
2014-06-26 23:50:33 +02:00
|
|
|
|
|
|
|
callback(null);
|
2013-06-23 13:37:01 +02:00
|
|
|
});
|
|
|
|
} else {
|
2014-06-26 23:50:33 +02:00
|
|
|
callback(true);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.commands = {
|
|
|
|
'~warn': function(event) {
|
|
|
|
var warner = event.rUser,
|
|
|
|
server = event.server,
|
|
|
|
reason = event.input[2];
|
|
|
|
|
|
|
|
this.api.warn(server, warner, event.input[1], reason, event.channel, function(err) {
|
|
|
|
if(err) {
|
2013-06-23 13:37:01 +02:00
|
|
|
event.reply(dbot.t('warnee_not_found', { 'user': event.input[1] }));
|
|
|
|
}
|
2014-06-26 23:50:33 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
'~rmwarning': function(event) {
|
|
|
|
var warning = null;
|
2014-09-04 15:43:53 +02:00
|
|
|
dbot.api.users.resolveUser(event.server, event.input[1], function(err, warnee) {
|
2014-06-26 23:50:33 +02:00
|
|
|
if(warnee) {
|
|
|
|
this.db.search('warnings', { 'warnee': warnee.id, 'reason': event.input[2] }, function(result) {
|
|
|
|
warning = result;
|
|
|
|
}, function(err) {
|
|
|
|
if(!err && warning) {
|
|
|
|
this.db.del('warnings', warning.id, function(err) {
|
|
|
|
event.reply(dbot.t('warning_removed'));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('warning_not_found'));
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('warning_not_found'));
|
|
|
|
}
|
2013-06-23 13:37:01 +02:00
|
|
|
}.bind(this));
|
2013-06-19 02:06:52 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~warnings': function(event) {
|
|
|
|
var warnee = event.params[1],
|
|
|
|
server = event.server;
|
|
|
|
|
2014-09-04 15:43:53 +02:00
|
|
|
dbot.api.users.resolveUser(server, warnee, function(err, warnee) {
|
2014-11-09 14:59:00 +01:00
|
|
|
if(warnee) {
|
|
|
|
var warnings = 0;
|
|
|
|
this.db.search('warnings', {
|
|
|
|
'server': server,
|
|
|
|
'warnee': warnee.id
|
|
|
|
}, function(warning) {
|
|
|
|
warnings++;
|
|
|
|
}, function(err) {
|
|
|
|
if(warnings > 0) {
|
|
|
|
event.reply(dbot.t('warning_info', {
|
|
|
|
'user': warnee.primaryNick,
|
|
|
|
'num': warnings,
|
|
|
|
'url': dbot.api.web.getUrl('warning/' + server + '/'
|
|
|
|
+ warnee.primaryNick)
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('no_warnings', { 'user':
|
|
|
|
warnee.primaryNick }));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply(event.params[1] + ' not found.');
|
|
|
|
}
|
2013-06-23 13:37:01 +02:00
|
|
|
}.bind(this));
|
2013-06-19 02:06:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-29 19:38:24 +01:00
|
|
|
this.commands['~warn'].regex = [/warn ([^ ]+) (.+)/, 3];
|
2013-09-24 13:52:23 +02:00
|
|
|
this.commands['~warn'].access = 'power_user';
|
2014-06-26 23:50:33 +02:00
|
|
|
this.commands['~rmwarning'].regex = [/^rmwarning ([\d\w\s\-]+?)[ ]?=[ ]?(.+)$/, 3];
|
|
|
|
this.commands['~rmwarning'].access = 'power_user';
|
2013-06-19 02:06:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new warning(dbot);
|
|
|
|
};
|