diff --git a/modules/users/api.js b/modules/users/api.js index 9ed04a0..4edaf57 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -10,15 +10,19 @@ var api = function(dbot) { var api = { // Return a user record given a primary nick or an alias 'resolveUser': function(server, nick, callback) { + var found = false; if(_.has(this.userCache[server], nick)) { this.api.getUser(this.userCache[server][nick], callback); } else { this.db.search('users', { 'server': server }, function(result) { if(result.primaryNick == nick || _.include(result.aliases, nick)) { this.userCache[server][nick] = result.id; - return callback(result); + found = true; + callback(result); } - }.bind(this), function(err) {}); + }.bind(this), function(err) { + if(!found) callback(false); + }); } }, diff --git a/modules/users/users.js b/modules/users/users.js index 587c2da..eeda646 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -127,29 +127,18 @@ var users = function(dbot) { }.bind(this)); }.bind(this); var checkUser = function(done) { - var checkCurrentNick = function(user) { - if(event.user != user.currentNick) { - user.currentNick = event.user; - this.db.save('users', user.id, user, function() { - done(user); - }); + this.api.resolveUser(event.server, event.user, function(user) { + if(!user) { + this.internalAPI.createUser(event.server, event.user, done); } else { - done(user); - } - }.bind(this); - - if(_.has(this.userCache, event.server) && _.has(this.userCache[event.server], event.user)) { - this.api.getUser(this.userCache[event.server][event.user], checkCurrentNick); - } else { - this.api.resolveUser(event.server, event.user, function(user) { - if(!user) { - this.internalAPI.createUser(event.server, - event.user, checkCurrentNick); + if(event.user != user.currentNick) { + user.currentNick = event.user; + this.db.save('users', user.id, user, function() { done(user); }); } else { - checkCurrentNick(user); + done(user); } - }.bind(this)); - } + } + }); }.bind(this); var checkChannelUsers = function(done) { var needsUpdating = false; @@ -201,7 +190,6 @@ var users = function(dbot) { checkUser(function(user) { event.rUser = user; - if(!_.has(this.userCache, event.server)) this.userCache[event.server] = {}; if(!_.has(this.userCache[event.server], event.rUser.currentNick)) { this.userCache[event.server][event.rUser.currentNick] = event.rUser.id; } else if(this.userCache[event.server][event.rUser.currentNick] != event.rUser.id) {