From bc771659370d3147e89d7fb1d4defb8e2e06b466 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Tue, 17 Jun 2014 22:30:17 +0200 Subject: [PATCH] Run commands on connect --- config.js | 9 ++++++--- lib/server.js | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) 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;