dbot/modules-stock/poll/poll.js
Georg 70a21d2b18
Signed-off-by: Georg <georg@lysergic.dev>
Init

- Initial fixes in modules
- Bundled adapted jsbot
- Elaborative README.md
2021-08-24 21:16:26 +02: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);
}