3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Fix ~setaliasparent [#272]

This commit is contained in:
reality 2013-03-24 16:59:26 +00:00
parent 3814df98f6
commit 17c2c4b317
3 changed files with 13 additions and 10 deletions

View File

@ -15,7 +15,6 @@ var api = function(dbot) {
'resolveUser': function(server, nick, callback) {
var user = false;
this.db.search('users', { 'server': server }, function(result) {
console.log(result.primaryNick);
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
user = result;
}

View File

@ -36,14 +36,19 @@ var commands = function(dbot) {
'~setaliasparent': function(event) {
var newPrimary = event.params[1].trim();
this.api.resolveUser(event.server, newPrimary, function(user) {
if(user) {
if(user && user.primaryNick != newPrimary) {
var newAlias = user.primaryNick;
user.primaryNick = newPrimary;
user.aliases = _.without(user.aliases, newPrimary).push(newAlias);
user.aliases = _.without(user.aliases, newPrimary);
user.aliases.push(newAlias);
this.internalAPI.updateChannelPrimaryUser(event.server, newAlias, newPrimary);
this.db.save('users', user.id, user, function(err) {
if(!err) {
event.reply(dbot.t('aliasparentset', {
'newParent': newPrimary,
'newAlias': newAlias
}));
dbot.api.event.emit('~setaliasparent', {
'server': event.server,
'alias': newAlias
@ -51,7 +56,7 @@ var commands = function(dbot) {
}
});
} else {
event.reply(dbot.t('unknown_alias', { 'alias': newParent }));
event.reply(dbot.t('unknown_alias', { 'alias': newPrimary }));
}
}.bind(this));
},
@ -80,17 +85,17 @@ var commands = function(dbot) {
'secondary': secondaryUser
});
}
});
}.bind(this));
}
});
}.bind(this));
} else {
event.reply(dbot.t('unprimary_error'));
}
});
}.bind(this));
} else {
event.reply(dbot.t('unprimary_error'));
}
});
}.bind(this));
}
};

View File

@ -42,7 +42,7 @@ var users = function(dbot) {
});
});
}
});
}.bind(this));
}.bind(this),
'updateChannelPrimaryUser': function(server, oldUser, newUser) {
@ -82,7 +82,6 @@ var users = function(dbot) {
this.api.isKnownUser(event.server, event.newNick, function(isKnown) {
if(!isKnown) {
this.api.resolveUser(event.server, event.user, function(user) {
dbot.say('aberwiki', '#realitest', event.newNick);
user.aliases.push(event.newNick);
this.db.save('users', user.id, user, function(err) {
if(!err) {