Run commands on connect

This commit is contained in:
Mattias Erming 2014-06-17 22:30:17 +02:00
parent 58103b9954
commit bc77165937
2 changed files with 26 additions and 6 deletions

View File

@ -9,8 +9,11 @@ module.exports = {
networks: [{
host: "irc.freenode.org",
port: 6667,
channels: [
"#shout-irc",
],
onConnect: {
commands: [""],
join: [
"#shout-irc",
]
}
}]
};

View File

@ -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;