hook for update poll nicks [#158][#166] also change mergeusers return api

This commit is contained in:
reality 2013-01-20 20:22:27 +00:00
parent f04621a5e9
commit 07656eddcd
2 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,23 @@
var poll = function(dbot) { var poll = function(dbot) {
this.internalAPI = {
'updatePollNicks': function(server, oldNick) {
var newNick = dbot.api.users.resolveUser(server, oldNick);
_.each(dbot.db.polls, function(poll) {
if(poll.owner === oldNick) {
poll.owner = newNick;
}
if(_.has(poll.votees, oldNick)) {
poll.votees[newNick] = poll.votees[oldNick];
delete poll.votees[oldNick];
}
}, this);
}
};
this.onLoad = function() {
dbot.api.command.addHook('~setaliasparent', this.internalAPI.updatePollNicks);
dbot.api.command.addHook('~mergeusers', this.internalAPI.updatePollNicks);
}.bind(this);
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {

View File

@ -92,7 +92,6 @@ var commands = function(dbot) {
return { return {
'server': event.server, 'server': event.server,
'primary': primaryUser,
'secondary': secondaryUser 'secondary': secondaryUser
}; };
} else { } else {