3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 12:12:35 +01:00
dbot/modules/poll/poll.js
2013-05-26 13:11:09 +00:00

30 lines
986 B
JavaScript

var poll = function(dbot) {
this.internalAPI = {
'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;
}
if(_.has(poll.votees, oldUser.id)) {
poll.votes[poll.votees[oldUser.id]]--;
delete poll.votees[oldUser.id];
needsUpdating = true;
}
if(needsUpdating) {
this.db.save('poll', poll.name, poll, function(err) {});
}
}.bind(this), function(err) {});
}.bind(this)
};
this.onLoad = function() {
dbot.api.event.addHook('~mergeusers', this.internalAPI.updatePollNicks);
}.bind(this);
};
exports.fetch = function(dbot) {
return new poll(dbot);
}