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

Commit

Permalink
Use event.once instead of event.on for one-time events.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Aug 8, 2012
1 parent e59862f commit 2e7f01c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions standup-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ var commands = {
project = project.slice(1);
}
var ret = api.status.create(user, project, args.slice(1).join(' '));
ret.on('ok', function(data) {
ret.once('ok', function(data) {
client.say(channel, 'Ok, submitted status #' + data.id);
});
ret.on('error', function(err, data) {
ret.once('error', function(err, data) {
client.say(channel, 'Uh oh, something went wrong.');
});
});
Expand All @@ -168,10 +168,10 @@ var commands = {
'delete': function(user, channel, message, args) {
utils.ifAuthorized(user, channel, function() {
var ret = api.status.delete_(args[0], user);
ret.on('ok', function(data) {
ret.once('ok', function(data) {
client.say(channel, 'Ok, status #' + args + ' is no more!');
});
ret.on('error', function(code, data) {
ret.once('error', function(code, data) {
if (code === 403) {
client.say(channel, "You don't have permissiont to do that. " +
"Do you own that status?");
Expand All @@ -198,10 +198,10 @@ var commands = {
/* Check a user's authorization status. */
'trust': function(user, channel, message, args) {
var a = authman.checkUser(args);
a.on('authorized', function() {
a.once('authorized', function() {
client.say(channel, 'I trust ' + args);
});
a.on('unauthorized', function() {
a.once('unauthorized', function() {
client.say(channel, "I don't trust " + args);
});
},
Expand Down
8 changes: 4 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function request(path, method, data, emitter) {
resp_data += chunk;
});
// When we have received the entire response
res.on('end', function() {
res.once('end', function() {
if (res.statusCode === 200) {
var json = JSON.parse(resp_data);
emitter.emit('ok', json);
Expand All @@ -42,7 +42,7 @@ function request(path, method, data, emitter) {
});
});
req.end(body);
req.on('error', function(e) {
req.once('error', function(e) {
logger.error(options.host + ':' + options.port + options.path +
': ' + JSON.stringify(data));
emitter.emit('error', String(e));
Expand All @@ -55,8 +55,8 @@ this.request = request;

this.ifAuthorized = function(user, channel, func) {
var a = authman.checkUser(user);
a.on('authorized', func);
a.on('unauthorized', function() {
a.once('authorized', func);
a.once('unauthorized', function() {
client.say(channel, "I don't trust you, " + user + ", " +
"are you identified with nickserv?");
});
Expand Down

0 comments on commit 2e7f01c

Please sign in to comment.