From 07656eddcde212f93ff0a9957beffb935333f932 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 20 Jan 2013 20:22:27 +0000 Subject: [PATCH] hook for update poll nicks [#158][#166] also change mergeusers return api --- modules/poll/poll.js | 19 +++++++++++++++++++ modules/users/commands.js | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/poll/poll.js b/modules/poll/poll.js index bda9b6d..1110faa 100644 --- a/modules/poll/poll.js +++ b/modules/poll/poll.js @@ -1,4 +1,23 @@ 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) { diff --git a/modules/users/commands.js b/modules/users/commands.js index 32c5867..ed1d561 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -92,7 +92,6 @@ var commands = function(dbot) { return { 'server': event.server, - 'primary': primaryUser, 'secondary': secondaryUser }; } else {