Skip to content

Instantly share code, notes, and snippets.

@TrainerGuy22
Created June 6, 2014 03:10
Show Gist options
  • Select an option

  • Save TrainerGuy22/eeb424339a5511ca6f62 to your computer and use it in GitHub Desktop.

Select an option

Save TrainerGuy22/eeb424339a5511ca6f62 to your computer and use it in GitHub Desktop.
/* jslint node: true */
"use strict";
var net = require('net'),
chalk = require('chalk'),
events = require('events'),
colors = require('irc-colors'),
treestump = require('../../treestump');
function NodeicusBot(hostname, port, callback) {
var logger = treestump.Logger("nodeicus");
var emitter = new events.EventEmitter();
var stdout = treestump.Mirrors.stdout();
stdout.setFormat(chalk.yellow("{{time}} {{level}} ->") + " {{message}}");
logger.addMirror(stdout);
var socket = net.connect({
'port': port,
'host': hostname
}, function() {
callback();
});
return {
addCommandHandler: function(name, callback) {
emitter.on('command', function(name1, message) {
if(name === name1) {
callback(message);
}
});
},
addRawHandler: function(name, callback) {
emitter.on('raw', function(name1, args) {
if(name === name1) {
callback(args);
}
});
},
addMessageHandler: function(name, callback) {
emitter.on('message', function(name1, message) {
if(name === name1) {
callback(message);
}
});
},
sendRaw: function(text) {
logger.info(chalk.green("SENT ") + text);
socket.write(text + "\r\n");
},
joinChannel: function(channel) {
this.sendRaw("JOIN " + channel);
},
sendMessage: function(channel, message) {
this.sendRaw("PRIVMSG " + channel + " :" + message);
},
getEmitter: function() {
return emitter;
},
getLogger: function() {
return logger;
},
getSocket: function() {
return socket;
}
};
};
module.exports = NodeicusBot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment