From 5b8c10a61103fd6b68885c513f7a0ad23f8e7d70 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 May 2011 13:59:54 +0200 Subject: prepare import into krebscode/painload --- README.md | 12 ---- modules/roboctl/index.js | 162 +++++++++++++++++++++++++++++++++++++++++++++ modules/roboctl/lib/irc.js | 67 +++++++++++++++++++ src/lib/irc.js | 67 ------------------- src/main.js | 162 --------------------------------------------- 5 files changed, 229 insertions(+), 241 deletions(-) delete mode 100644 README.md create mode 100644 modules/roboctl/index.js create mode 100644 modules/roboctl/lib/irc.js delete mode 100644 src/lib/irc.js delete mode 100644 src/main.js diff --git a/README.md b/README.md deleted file mode 100644 index f324d221..00000000 --- a/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Genericore irclog - -This package contains a Genericore output module to forward logs to IRC. - -*Please note that this is early development software - that lacks proper documentation, tests, and a lot of useful or even necessary features.* - -## System requirements - -- [node](http://nodejs.org/) v0.2.5 or compatible -- [node-amqp](https://github.com/ry/node-amqp) v0.0.2 or compatible - diff --git a/modules/roboctl/index.js b/modules/roboctl/index.js new file mode 100644 index 00000000..b9e67a19 --- /dev/null +++ b/modules/roboctl/index.js @@ -0,0 +1,162 @@ + +var connect = require('genericore').connect; + +var config = { + irc: {} +}; + +connect(config.irc, { + debug: function (message) { + }, + ready: function (client) { + + } +}); + + + +// { +// userName: 'nodebot', +// realName: 'nodeJS IRC client', +// port: 6667, +// debug: false, +// showErrors: false, +// autoRejoin: true, +// channels: [], +// secure: false +// } + +var config = { + "irc": { + "nick": "a43243afds", + "server": "irc.freenode.net", + "port": 6667, + "channel": "#genericoredump" + }, + "amqp": { + "reconnect_timeout": 10000, + "connection": { + "host": "141.31.8.11", + "port": 5672, + "login": "shack", + "password": "shackit", + "vhost": "/" + }, + "exchange": { + "name": "log", + "options": { + "type": "fanout", + "passive": false, + "durable": false, + "auto_delete": false, + "internal": false, + "nowait": false + } + }, + "queue": { + "name": "irclog2", + "options": { + "passive": false, + "durable": false, + "exclusive": false, + "autoDelete": false, + "nowait": false + } + } + } +}; + +//var irc = require('./lib/irc'); +var irc = require('./lib/irc').createClient(config.irc); +var amqp = require('amqp'); + +// TODO var amqp = require('./lib/amqp').createClient(config.amqp); +// where createClient will bind to all connected (exchange,queue) pairs +// irc.connect({ +// ready: function () { +// amqp.connect({ +// message: function (message) { +// console.log(message); +// irc.privmsg(config.irc.channel, message.data); +// } +// }); +// } +// }); + +// TODO call back when joined +irc.connect(function () { + var connection = amqp.createConnection(config.amqp.connection); + connection.on('ready', function () { + var queue = connection.queue(config.amqp.queue.name, config.amqp.queue.options); + + queue.bind(config.amqp.exchange.name, config.amqp.queue.name); + + console.log('receiving messages'); + queue.subscribe(function (message) { + console.log(message.data); + irc.write(message.data); + }); + }); +}); + +// amqp.connect(function () { +// amqp.connection.exchange("log", config.amqp.exchange.options).on( +// 'open', function () { +// log = function (message) { +// exchange.publish(config.amqp.exchange.name, message); +// }; +// } +// ); +// +// tcp.serve(function (message) { +// var data = parse(message); +// log('[mailsrc,tcp] incoming: ' + data['Header-Fields']['Subject']); +// console.log('publishing: ' + data['Header-Fields'].From); +// amqp.publish({ type: 'mail', subtype: 0, data: data }); +// }); +// }); +// +// +// var client = new irc.Client(config.server, config.nick, { +// channels: [config.channel], +// }); +// +// client.on('error', function (err) { +// console.log('>>>\n' + require('sys').inspect(err)); +// }); +// +// +// var amqp = require('amqp'); +// client.join(config.channel, function () { +// +// var connection = amqp.createConnection(config.amqp.connection); +// +// // Wait for connection to become established. +// connection.on('ready', function () { +// // Create a queue and bind to all messages. +// // Use the default 'amq.topic' exchange +// var q = connection.queue(config.amqp.queue.name, config.amqp.queue); +// // Catch all messages +// q.bind(config.amqp.exchange.name, config.amqp.queue.name); +// +// // Receive messages +// console.log('receiving messages'); +// q.subscribe(function (message) { +// // Print messages to stdout +// console.log(message); +// client.say(config.channel, message.data); +// }); +// }); +// }); + + + + + +// client.on('pm', function (from, message) { +// sys.puts(from + ' => ME: ' + message); +// }); +// +// client.on('message#yourchannel', function (from, message) { +// sys.puts(from + ' => #yourchannel: ' + message); +// }); diff --git a/modules/roboctl/lib/irc.js b/modules/roboctl/lib/irc.js new file mode 100644 index 00000000..5f904a74 --- /dev/null +++ b/modules/roboctl/lib/irc.js @@ -0,0 +1,67 @@ + +var Client = function (config) { + var client = this; + var net = require('net'); + var sys = require('sys'); + var log = function (x) { + sys.puts('TCP server: ' + x); + }; + + client.connect = function (callback) { + var stream = net.createConnection(config.port, config.server); + stream.on('connect', function () { + stream.write( + 'NICK ' + config.nick + '\n' + + 'USER ' + config.nick + ' 0 *:Karl Koch\n' + + 'JOIN ' + config.channel + '\n' + ); + //client.write = function (text) { + // stream.write('PRIVMSG ' + config.channel + ' :' + text); + //}; + client.write = msg_start_send; + callback(); + }); + //stream.on('secure', function () { + //}); + + var msg = []; + + var msg_start_send = function (x) { + client.write = msg_append; + setTimeout(function () { + var x = msg.join('\n') + '\n'; + msg = []; + client.write = msg_start_send; + stream.write('PRIVMSG ' + config.channel + ' :' + x); + }, 1000); + }; + + var msg_append = function (x) { + msg[msg.length] = x; + }; + + + stream.on('data', function (data) { + data = String(data); + log('' + data + ''); + if (data.substring(0,4) === 'PING') { + log('PONG!'); + stream.write('PONG ' + data.substring(4)); + } + }); + //stream.on('end', function () { + //}); + //stream.on('timeout', function () { + //}); + //stream.on('drain', function () { + //}); + //stream.on('error', function (exception) { + //}); + //stream.on('clonse', function (exception) { + //}); + }; +}; + +exports.createClient = function (config) { + return new Client(config); +}; diff --git a/src/lib/irc.js b/src/lib/irc.js deleted file mode 100644 index 5f904a74..00000000 --- a/src/lib/irc.js +++ /dev/null @@ -1,67 +0,0 @@ - -var Client = function (config) { - var client = this; - var net = require('net'); - var sys = require('sys'); - var log = function (x) { - sys.puts('TCP server: ' + x); - }; - - client.connect = function (callback) { - var stream = net.createConnection(config.port, config.server); - stream.on('connect', function () { - stream.write( - 'NICK ' + config.nick + '\n' + - 'USER ' + config.nick + ' 0 *:Karl Koch\n' + - 'JOIN ' + config.channel + '\n' - ); - //client.write = function (text) { - // stream.write('PRIVMSG ' + config.channel + ' :' + text); - //}; - client.write = msg_start_send; - callback(); - }); - //stream.on('secure', function () { - //}); - - var msg = []; - - var msg_start_send = function (x) { - client.write = msg_append; - setTimeout(function () { - var x = msg.join('\n') + '\n'; - msg = []; - client.write = msg_start_send; - stream.write('PRIVMSG ' + config.channel + ' :' + x); - }, 1000); - }; - - var msg_append = function (x) { - msg[msg.length] = x; - }; - - - stream.on('data', function (data) { - data = String(data); - log('' + data + ''); - if (data.substring(0,4) === 'PING') { - log('PONG!'); - stream.write('PONG ' + data.substring(4)); - } - }); - //stream.on('end', function () { - //}); - //stream.on('timeout', function () { - //}); - //stream.on('drain', function () { - //}); - //stream.on('error', function (exception) { - //}); - //stream.on('clonse', function (exception) { - //}); - }; -}; - -exports.createClient = function (config) { - return new Client(config); -}; diff --git a/src/main.js b/src/main.js deleted file mode 100644 index b9e67a19..00000000 --- a/src/main.js +++ /dev/null @@ -1,162 +0,0 @@ - -var connect = require('genericore').connect; - -var config = { - irc: {} -}; - -connect(config.irc, { - debug: function (message) { - }, - ready: function (client) { - - } -}); - - - -// { -// userName: 'nodebot', -// realName: 'nodeJS IRC client', -// port: 6667, -// debug: false, -// showErrors: false, -// autoRejoin: true, -// channels: [], -// secure: false -// } - -var config = { - "irc": { - "nick": "a43243afds", - "server": "irc.freenode.net", - "port": 6667, - "channel": "#genericoredump" - }, - "amqp": { - "reconnect_timeout": 10000, - "connection": { - "host": "141.31.8.11", - "port": 5672, - "login": "shack", - "password": "shackit", - "vhost": "/" - }, - "exchange": { - "name": "log", - "options": { - "type": "fanout", - "passive": false, - "durable": false, - "auto_delete": false, - "internal": false, - "nowait": false - } - }, - "queue": { - "name": "irclog2", - "options": { - "passive": false, - "durable": false, - "exclusive": false, - "autoDelete": false, - "nowait": false - } - } - } -}; - -//var irc = require('./lib/irc'); -var irc = require('./lib/irc').createClient(config.irc); -var amqp = require('amqp'); - -// TODO var amqp = require('./lib/amqp').createClient(config.amqp); -// where createClient will bind to all connected (exchange,queue) pairs -// irc.connect({ -// ready: function () { -// amqp.connect({ -// message: function (message) { -// console.log(message); -// irc.privmsg(config.irc.channel, message.data); -// } -// }); -// } -// }); - -// TODO call back when joined -irc.connect(function () { - var connection = amqp.createConnection(config.amqp.connection); - connection.on('ready', function () { - var queue = connection.queue(config.amqp.queue.name, config.amqp.queue.options); - - queue.bind(config.amqp.exchange.name, config.amqp.queue.name); - - console.log('receiving messages'); - queue.subscribe(function (message) { - console.log(message.data); - irc.write(message.data); - }); - }); -}); - -// amqp.connect(function () { -// amqp.connection.exchange("log", config.amqp.exchange.options).on( -// 'open', function () { -// log = function (message) { -// exchange.publish(config.amqp.exchange.name, message); -// }; -// } -// ); -// -// tcp.serve(function (message) { -// var data = parse(message); -// log('[mailsrc,tcp] incoming: ' + data['Header-Fields']['Subject']); -// console.log('publishing: ' + data['Header-Fields'].From); -// amqp.publish({ type: 'mail', subtype: 0, data: data }); -// }); -// }); -// -// -// var client = new irc.Client(config.server, config.nick, { -// channels: [config.channel], -// }); -// -// client.on('error', function (err) { -// console.log('>>>\n' + require('sys').inspect(err)); -// }); -// -// -// var amqp = require('amqp'); -// client.join(config.channel, function () { -// -// var connection = amqp.createConnection(config.amqp.connection); -// -// // Wait for connection to become established. -// connection.on('ready', function () { -// // Create a queue and bind to all messages. -// // Use the default 'amq.topic' exchange -// var q = connection.queue(config.amqp.queue.name, config.amqp.queue); -// // Catch all messages -// q.bind(config.amqp.exchange.name, config.amqp.queue.name); -// -// // Receive messages -// console.log('receiving messages'); -// q.subscribe(function (message) { -// // Print messages to stdout -// console.log(message); -// client.say(config.channel, message.data); -// }); -// }); -// }); - - - - - -// client.on('pm', function (from, message) { -// sys.puts(from + ' => ME: ' + message); -// }); -// -// client.on('message#yourchannel', function (from, message) { -// sys.puts(from + ' => #yourchannel: ' + message); -// }); -- cgit v1.2.3