Added config and auto-connect

This commit is contained in:
Mattias Erming 2014-04-06 00:01:19 +02:00
parent 2ca64df5d2
commit a23a446145
3 changed files with 38 additions and 8 deletions

11
config.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = {
port: 9000,
defaults: {
nick: "t_user",
realname: "Temp User",
},
servers: [{
host: "irc.freenode.org",
channels: ["#t_chan"],
}]
};

View File

@ -1,7 +1,8 @@
var models = require(__dirname + "/models.js");
var config = require(__dirname + "/../config.js");
var http = require("connect");
var io = require("socket.io");
var irc = require("slate-irc");
var models = require(__dirname + "/models");
var net = require("net");
var _ = require("lodash");
@ -20,7 +21,7 @@ var events = [
"quit",
"topic",
"welcome",
"whois"
"whois",
];
module.exports = function listen() {
@ -36,11 +37,23 @@ module.exports = function listen() {
networks.on("all", function() {
sockets.emit.apply(sockets, arguments);
});
config.servers.forEach(function(s) {
connect(s);
});
};
function connect(host) {
function connect(params) {
params = _.extend(
config.defaults,
params
);
var host = params.host;
var port = params.port || 6667;
var stream = net.connect({
port: 6667,
port: port,
host: host,
});
@ -56,8 +69,14 @@ function connect(host) {
networks.trigger("network", networks);
client.nick("t_user");
client.user("t_user", "temp user");
client.nick(params.nick);
client.user(params.nick, params.realname);
client.once("welcome", function() {
params.channels.forEach(function(c) {
client.join(c);
});
});
events.forEach(function(e) {
client.on(e, function() {
@ -106,7 +125,7 @@ function input(json) {
case "server":
case "connect":
if (args[1]) {
connect(args[1]);
connect({host: args[1]});
}
break;