3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00
dbot/modules/poll/poll.js

30 lines
986 B
JavaScript
Raw Normal View History

var poll = function(dbot) {
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-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-05-26 15:11:09 +02:00
if(needsUpdating) {
this.db.save('poll', poll.name, poll, function(err) {});
}
}.bind(this), function(err) {});
}.bind(this)
};
this.onLoad = function() {
2013-05-26 15:11:09 +02:00
dbot.api.event.addHook('~mergeusers', this.internalAPI.updatePollNicks);
}.bind(this);
};
exports.fetch = function(dbot) {
2013-01-15 17:21:43 +01:00
return new poll(dbot);
}