summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@also>2011-01-21 23:48:24 +0100
committertv <tv@also>2011-01-21 23:48:24 +0100
commit8e4a4e7a5c8b3adce4a6c33a305093aee8221201 (patch)
tree2f25e6eb32ad3fcc2a1225bba84fb7ad9ae9218d
parent1eb3e2017502ddb94cc57e7edc2812893b686163 (diff)
WIP commit
-rw-r--r--README.md1
-rw-r--r--src/lib/irc.js67
-rw-r--r--src/main.js162
3 files changed, 229 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0ef38df3..f324d221 100644
--- a/README.md
+++ b/README.md
@@ -9,5 +9,4 @@ This package contains a Genericore output module to forward logs to IRC.
- [node](http://nodejs.org/) v0.2.5 or compatible
- [node-amqp](https://github.com/ry/node-amqp) v0.0.2 or compatible
-- [node-irc](https://github.com/martynsmith/node-irc) v0.1.2 or compatible
diff --git a/src/lib/irc.js b/src/lib/irc.js
new file mode 100644
index 00000000..5f904a74
--- /dev/null
+++ b/src/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/main.js b/src/main.js
new file mode 100644
index 00000000..b9e67a19
--- /dev/null
+++ b/src/main.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);
+// });