Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Commit

Permalink
Refactor trust callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Aug 14, 2012
1 parent 73e8e61 commit 603ec26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
18 changes: 9 additions & 9 deletions auth.js
Expand Up @@ -29,24 +29,24 @@ 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);
}
}
};

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;
};

Expand Down
13 changes: 7 additions & 6 deletions standup-irc.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
});
},

Expand Down
21 changes: 8 additions & 13 deletions utils.js
Expand Up @@ -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;
};

0 comments on commit 603ec26

Please sign in to comment.