From 17c2c4b317cac74168313f535cea31145a7f9a36 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 24 Mar 2013 16:59:26 +0000 Subject: [PATCH] Fix ~setaliasparent [#272] --- modules/users/api.js | 1 - modules/users/commands.js | 19 ++++++++++++------- modules/users/users.js | 3 +-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index b187e8c..f779941 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -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; } diff --git a/modules/users/commands.js b/modules/users/commands.js index 4b5fc46..8dbead1 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -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)); } }; diff --git a/modules/users/users.js b/modules/users/users.js index b1d1177..d32f4c0 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -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) {