diff --git a/config.js b/config.js index d2c5b96e..df959c01 100644 --- a/config.js +++ b/config.js @@ -9,8 +9,11 @@ module.exports = { networks: [{ host: "irc.freenode.org", port: 6667, - channels: [ - "#shout-irc", - ], + onConnect: { + commands: [""], + join: [ + "#shout-irc", + ] + } }] }; diff --git a/lib/server.js b/lib/server.js index b04413cb..f5e00b98 100644 --- a/lib/server.js +++ b/lib/server.js @@ -115,12 +115,28 @@ function connect(params) { client.user(params.nick, params.realname); client.once("welcome", function() { - (params.channels || []).forEach(function(c) { + (params.onConnect.join || []).forEach(function(chan) { client.join.apply( client, - c.split(' ') + chan.split(' ') ); }); + + // Trigger 'PONG' response. + client.write("PING " + network.host); + }); + + client.once("pong", function() { + var delay = 1000; + (params.onConnect.commands || []).forEach(function(cmd) { + setTimeout(function() { + input({ + id: network.channels[0].id, + text: cmd + }); + }, delay); + delay += 1000; + }); }); events.forEach(function(e) { @@ -142,7 +158,6 @@ function debug(data) { } function input(data) { - var socket = this; var target = find(data.id); if (!target) { return; @@ -300,6 +315,8 @@ function input(data) { network.channels.forEach(function(c) { if (c.type == "channel") part.push(c.name); }); + console.log("PART"); + console.log(part); client.part(part); break;