This commit is contained in:
reality 2016-02-19 19:12:22 +00:00
parent da8c297973
commit c247f48fbe

View File

@ -63,24 +63,38 @@ var warning = function(dbot) {
}, },
'~rmwarning': function(event) { '~rmwarning': function(event) {
var warning = null; var user = event.params[1],
dbot.api.users.resolveUser(event.server, event.input[1], function(err, warnee) { index = parseInt(event.params[2]);
if(warnee) {
this.db.search('warnings', { 'warnee': warnee.id, 'reason': event.input[2] }, function(result) { dbot.api.users.resolveUser(event.server, user, function(err, warnee) {
warning = result; if(warnee) {
}, function(err) { var warns = {};
if(!err && warning) {
this.db.del('warnings', warning.id, function(err) { dbot.api.getUserAlises(warnee.id, function(err, aliases) {
event.reply(dbot.t('warning_removed')); var alia = aliases.push(warnee.primaryNick);
}); this.db.search('notifies', {
} else { 'server': warnee.id,
event.reply(dbot.t('warning_not_found')); 'type': 'warn'
} }, function(result) {
}.bind(this)); if(_.include(alia, result.target)) {
} else { warns[result.time] = result;
event.reply(dbot.t('warning_not_found')); }
} }, function(err) {
}.bind(this)); var sTimes = _.keys(warns).sort(function(a, b) {
return parseInt(a) - parseInt(b);
});
if(index < sTimes.length && index > 0) {
this.db.del('notifies', warns[sTimes[index]], function(err) {
event.reply(dbot.t('warning_removed'));
});
} else {
event.reply(dbot.t('warning_not_found'));
}
}.bind(this));
});
}
});
}, },
'~rmlastwarning': function(event) { '~rmlastwarning': function(event) {
@ -135,7 +149,6 @@ var warning = function(dbot) {
this.commands['~warn'].regex = [/warn ([^ ]+) (.+)/, 3]; this.commands['~warn'].regex = [/warn ([^ ]+) (.+)/, 3];
this.commands['~warn'].access = 'power_user'; this.commands['~warn'].access = 'power_user';
this.commands['~rmwarning'].regex = [/^rmwarning ([\d\w\s\-]+?)[ ]?=[ ]?(.+)$/, 3];
this.commands['~rmwarning'].access = 'power_user'; this.commands['~rmwarning'].access = 'power_user';
this.commands['~rmlastwarning'].access = 'power_user'; this.commands['~rmlastwarning'].access = 'power_user';
}; };