Created
February 22, 2012 03:23
-
-
Save nbqx/1881056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var events = require('events'); | |
var spawn = require('child_process').spawn; | |
var irc = require('irc'); | |
function NBot(cmd,opt){ | |
var self = this; | |
self.cmd = cmd; | |
self.opt = opt; | |
events.EventEmitter.call(self); | |
}; | |
util.inherits(NBot, events.EventEmitter); | |
NBot.prototype.start = function(sm,cb){ | |
var self = this; | |
self.emit('start',sm); | |
self.exec = spawn(self.cmd, self.opt); | |
self.exec.stdout.on('data', function(data){ | |
console.log(data.toString('utf8')); | |
}); | |
self.exec.on('exit', function(){ | |
cb(); | |
}); | |
}; | |
//irc server setting | |
var server = "ADDRESS"; | |
var nick = "NICK"; | |
var chan = "#CHANNEL"; | |
//exec command | |
var cmd = "ruby"; | |
var cmd_opt = ["test.rb"]; //e.g. sleep 3;puts "rb done!" | |
var cl = new irc.Client(server, nick); | |
var bot = new NBot(cmd, cmd_opt); | |
bot.on('start', function(mes){ | |
cl.join(chan, function(){ | |
cl.say(chan, mes); | |
}); | |
}); | |
bot.start('start child_process', function(){ | |
cl.say(chan, "child_process done!"); | |
cl.disconnect(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment