forked from GitHub/dbot
fix various mergeusers hooks [#472]
This commit is contained in:
parent
5dddae4f00
commit
f69f999118
@ -2,7 +2,7 @@
|
||||
"dbType": "redis",
|
||||
"dbKeys": [ "polls" ],
|
||||
"ignorable": true,
|
||||
"dependencies": [ "users", "web" ],
|
||||
"dependencies": [ "users", "web", "event" ],
|
||||
"schema": {
|
||||
"poll": {
|
||||
"pkey": "name",
|
||||
|
@ -1,22 +1,26 @@
|
||||
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;
|
||||
'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, oldNick)) {
|
||||
poll.votees[newNick] = poll.votees[oldNick];
|
||||
delete poll.votees[oldNick];
|
||||
if(_.has(poll.votees, oldUser.id)) {
|
||||
poll.votes[poll.votees[oldUser.id]]--;
|
||||
delete poll.votees[oldUser.id];
|
||||
needsUpdating = true;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
if(needsUpdating) {
|
||||
this.db.save('poll', poll.name, poll, function(err) {});
|
||||
}
|
||||
}.bind(this), function(err) {});
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
this.onLoad = function() {
|
||||
// dbot.api.command.addHook('~setaliasparent', this.internalAPI.updatePollNicks);
|
||||
// dbot.api.command.addHook('~mergeusers', this.internalAPI.updatePollNicks);
|
||||
dbot.api.event.addHook('~mergeusers', this.internalAPI.updatePollNicks);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
|
@ -98,7 +98,7 @@ var commands = function(dbot) {
|
||||
if(secondaryUser) {
|
||||
user.aliases.push(oldUser.primaryNick);
|
||||
user.aliases.concat(oldUser.aliases);
|
||||
this.internalAPI.mergeChannelUsers(event.server, oldUser, primaryUser);
|
||||
this.internalAPI.mergeChannelUsers(event.server, oldUser, user);
|
||||
this.db.del('users', oldUser.id, function(err) {
|
||||
if(!err) {
|
||||
this.db.save('users', user.id, user, function(err) {
|
||||
@ -108,10 +108,11 @@ var commands = function(dbot) {
|
||||
'old_user': secondaryUser,
|
||||
'new_user': primaryUser
|
||||
}));
|
||||
dbot.api.event.emit('~mergeusers', {
|
||||
'server': event.server,
|
||||
'secondary': secondaryUser
|
||||
});
|
||||
dbot.api.event.emit('~mergeusers', [
|
||||
event.server,
|
||||
oldUser,
|
||||
user
|
||||
]);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -84,9 +84,9 @@ var users = function(dbot) {
|
||||
// QQ
|
||||
}
|
||||
});
|
||||
});
|
||||
}.bind(this));
|
||||
}, this);
|
||||
}
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
this.listener = function(event) {
|
||||
|
Loading…
Reference in New Issue
Block a user