Skip to content

Commit

Permalink
tightening event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Breed committed Jun 6, 2011
1 parent 665445f commit 6b92180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 2 additions & 6 deletions hack-bot.coffee
Expand Up @@ -34,13 +34,9 @@ quack = ( room ) ->
# eval JS in the sandbox
if /^eval (.+)/.test( msg.body )
sandbox.run /^eval (.+)/.exec(msg.body)[1], ( output ) ->
output = output.result.replace( /\n/g, ' ' )
room.speak output, logger
room.speak output.result.replace( /\n/g, ' ' ), logger


Reminder.listen( msg, room )
Phrases.listen( msg, room )
Search.listen( msg, room )
task.listen( msg, room ) for task in [Reminder, Phrases, Search]

# leave the room on exit
process.on 'SIGINT', ->
Expand Down
14 changes: 9 additions & 5 deletions hack-bot.js
Expand Up @@ -29,18 +29,22 @@ quack = function(room) {
room.speak("hai guys", logger);
}
return room.listen(function(msg) {
var task, _i, _len, _ref, _results;
if (msg.user_id === parseInt(bot_id)) {
return;
}
if (/^eval (.+)/.test(msg.body)) {
sandbox.run(/^eval (.+)/.exec(msg.body)[1], function(output) {
output = output.result.replace(/\n/g, ' ');
return room.speak(output, logger);
return room.speak(output.result.replace(/\n/g, ' '), logger);
});
}
Reminder.listen(msg, room);
Phrases.listen(msg, room);
return Search.listen(msg, room);
_ref = [Reminder, Phrases, Search];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
task = _ref[_i];
_results.push(task.listen(msg, room));
}
return _results;
});
});
return process.on('SIGINT', function() {
Expand Down

0 comments on commit 6b92180

Please sign in to comment.