From 2204c910b9fc74a2671442757962283ad0756fb3 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 4 Jan 2014 17:59:14 +0000 Subject: [PATCH] that will soh wye --- modules/users/api.js | 10 ++++++++-- modules/users/users.js | 29 +++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/users/api.js b/modules/users/api.js index a08c3cc..5649a95 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -24,12 +24,18 @@ var api = function(dbot) { } if(result.primaryNick == nick || _.include(result.aliases, nick)) { - this.userCache[server][nick] = result.id; user = result; } }.bind(this), function(err) { + if(user) { + if(!_.has(this.userCache[server], nick)) { + this.userCache[server][nick] = user.id; + } else if(this.userCache[server][nick] !== user.id) { + this.userCache[server][nick] = user.id; + } + } callback(user); - }); + }.bind(this)); } }, diff --git a/modules/users/users.js b/modules/users/users.js index a63e8e2..2eeccc5 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -97,7 +97,6 @@ var users = function(dbot) { this.listener = function(event) { this.api.isKnownUser(event.server, event.newNick, function(isKnown) { event.rUser.currentNick = event.newNick; - dbot.api.event.emit('new_current_nick', [ event.rUser ]); if(!isKnown) { event.rUser.aliases.push(event.newNick); @@ -120,20 +119,24 @@ var users = function(dbot) { // 6. Update staff channel lists var checkChannel = function(done) { - this.api.resolveChannel(event.server, event.channel.name, function(channel) { - if(!channel) { - this.internalAPI.createChannel(event.server, event.channel.name, done); - } else { - done(channel); - } - }.bind(this)); + if(event.channel) { + this.api.resolveChannel(event.server, event.channel.name, function(channel) { + if(!channel) { + this.internalAPI.createChannel(event.server, event.channel.name, done); + } else { + done(channel); + } + }.bind(this)); + } else { + done(null); + } }.bind(this); var checkUser = function(done) { this.api.resolveUser(event.server, event.user, function(user) { if(!user) { this.internalAPI.createUser(event.server, event.user, done); } else { - if(event.user != user.currentNick) { + if(event.user !== user.currentNick) { user.currentNick = event.user; this.db.save('users', user.id, user, function() { dbot.api.event.emit('new_current_nick', [ user ]); @@ -189,18 +192,12 @@ var users = function(dbot) { } }.bind(this); - if(event.user && event.channel && _.include(['JOIN', 'MODE', 'NICK', 'PRIVMSG'], event.action)) { + if(event.user && _.include(['JOIN', 'MODE', 'NICK', 'PRIVMSG'], event.action)) { checkChannel(function(channel) { event.rChannel = channel; checkUser(function(user) { event.rUser = user; - 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) { - this.userCache[event.server][event.rUser.currentNick] = event.rUser.id; - } - if(event.channel) { checkChannelUsers(function() { callback();