From 81401cec0f2977c8ce80c80294888668a96b5216 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 11 Oct 2014 22:44:56 +0200 Subject: [PATCH] Added network export function --- src/client.js | 16 +++++++++++++--- src/models/network.js | 23 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/client.js b/src/client.js index 0067ed3..df8eb12 100644 --- a/src/client.js +++ b/src/client.js @@ -120,9 +120,9 @@ Client.prototype.connect = function(args) { var config = Helper.getConfig(); var client = this; var server = { + name: args.name || "", host: args.host || "irc.freenode.org", port: args.port || (args.tls ? 6697 : 6667), - name: args.name || "", rejectUnauthorized: false }; @@ -164,11 +164,17 @@ Client.prototype.connect = function(args) { irc.user(username, realname); var network = new Network({ - host: server.host, name: server.name, - irc: irc + host: server.host, + port: server.port, + tls: args.tls, + password: args.password, + username: username, + realname: realname, }); + network.irc = irc; + client.networks.push(network); client.emit("network", { network: network @@ -312,3 +318,7 @@ Client.prototype.quit = function() { } }); }; + +Client.prototype.save = function() { + var networks = _.map(this.networks, function(n) { return n.export(); }); +}; diff --git a/src/models/network.js b/src/models/network.js index d0db073..88d4680 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -7,9 +7,15 @@ var id = 0; function Network(attr) { _.merge(this, _.extend({ + name: "", + host: "", + port: 6667, + tls: false, + password: "", + username: "", + realname: "", channels: [], connected: false, - host: "", id: id++, irc: null, }, attr)); @@ -21,7 +27,20 @@ function Network(attr) { Network.prototype.toJSON = function() { var json = _.extend(this, {nick: (this.irc || {}).me || ""}); - return _.omit(json, "irc"); + return _.omit(json, "irc", "password"); +}; + +Network.prototype.export = function() { + var network = _.pick( + this, + ["name", "host", "port", "tls", "password", "username", "realname"] + ); + network.nick = (this.irc || {}).me; + network.join = _.pluck( + _.where(this.channels, {type: "channel"}), + "name" + ); + return network; }; function prettify(host) {