2012-12-11 17:04:52 +01:00
|
|
|
var poll = function(dbot) {
|
2013-01-20 21:22:27 +01:00
|
|
|
this.internalAPI = {
|
2013-05-26 15:11:09 +02:00
|
|
|
'updatePollNicks': function(server, oldUser, newUser) {
|
|
|
|
this.db.scan('poll', function(poll) {
|
|
|
|
var needsUpdating = false;
|
|
|
|
if(poll.owner == oldUser.id) {
|
|
|
|
poll.owner = newUser.id;
|
|
|
|
needsUpdating = true;
|
2013-01-20 21:22:27 +01:00
|
|
|
}
|
2013-05-26 15:11:09 +02:00
|
|
|
if(_.has(poll.votees, oldUser.id)) {
|
|
|
|
poll.votes[poll.votees[oldUser.id]]--;
|
|
|
|
delete poll.votees[oldUser.id];
|
|
|
|
needsUpdating = true;
|
2013-01-20 21:22:27 +01:00
|
|
|
}
|
2013-05-26 15:11:09 +02:00
|
|
|
if(needsUpdating) {
|
|
|
|
this.db.save('poll', poll.name, poll, function(err) {});
|
|
|
|
}
|
|
|
|
}.bind(this), function(err) {});
|
|
|
|
}.bind(this)
|
2013-01-20 21:22:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onLoad = function() {
|
2013-05-26 15:11:09 +02:00
|
|
|
dbot.api.event.addHook('~mergeusers', this.internalAPI.updatePollNicks);
|
2013-01-20 21:22:27 +01:00
|
|
|
}.bind(this);
|
2012-12-11 17:04:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2013-01-15 17:21:43 +01:00
|
|
|
return new poll(dbot);
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|