From 603ec26d7a976d8b638e3fe1d60c10bd2c8fc0ff Mon Sep 17 00:00:00 2001 From: Mike Cooper Date: Tue, 14 Aug 2012 15:37:30 -0700 Subject: [PATCH] Refactor trust callbacks. --- auth.js | 18 +++++++++--------- standup-irc.js | 13 +++++++------ utils.js | 21 ++++++++------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/auth.js b/auth.js index 7bb37c9..3b5e140 100644 --- a/auth.js +++ b/auth.js @@ -29,10 +29,10 @@ this.AuthManager.prototype.notice = function(nick, message) { if (level >= this.neededLevel) { user.auth = true; - user.emitter.emit('authorized'); + user.emitter.emit('authorization', true); } else { user.auth = false; - user.emitter.emit('unauthorized'); + user.emitter.emit('authorization', false); } } }; @@ -40,13 +40,13 @@ this.AuthManager.prototype.notice = function(nick, message) { this.AuthManager.prototype.checkUser = function(nick) { var self = this; var user = this._user(nick); - if (user.auth) { - process.nextTick(function() { - user.emitter.emit('authorized'); - }); - } else { - self._askNickserv(nick); - } + process.nextTick(function() { + if (user.auth) { + user.emitter.emit('authorization', true); + } else { + self._askNickserv(nick); + } + }); return user.emitter; }; diff --git a/standup-irc.js b/standup-irc.js index 9723c17..4cb3a94 100644 --- a/standup-irc.js +++ b/standup-irc.js @@ -132,7 +132,7 @@ client.on('message', function(user, channel, msg) { client.on('notice', function(from, to, text) { if (from === undefined) { - console.log('Service Notice: ' + text); + logger.info('Service Notice: ' + text); from = ''; } from = from.toLowerCase(); @@ -198,11 +198,12 @@ var commands = { /* Check a user's authorization status. */ 'trust': function(user, channel, message, args) { var a = authman.checkUser(args); - a.once('authorized', function() { - client.say(channel, 'I trust ' + args); - }); - a.once('unauthorized', function() { - client.say(channel, "I don't trust " + args); + a.once('authorization', function(trust) { + if (trust) { + client.say(channel, 'I trust ' + args); + } else { + client.say(channel, "I don't trust " + args); + } }); }, diff --git a/utils.js b/utils.js index b3ea22b..229888b 100644 --- a/utils.js +++ b/utils.js @@ -56,19 +56,14 @@ this.request = request; this.ifAuthorized = function(user, channel, func) { var a = authman.checkUser(user); - function doTrust() { - a.removeListener(dontTrust); - func(); - } - - function dontTrust() { - a.removeListener(trust); - client.say(channel, "I don't trust you, " + user + ", " + - "are you identified with nickserv?"); - } - - a.once('authorized', doTrust); - a.once('unauthorized', dontTrust); + a.once('authorization', function(trust) { + if (trust) { + func(); + } else { + client.say(channel, "I don't trust you, " + user + ", " + + "are you identified with nickserv?"); + } + }); return a; };