diff --git a/.gitignore b/.gitignore index 1ca95717..c39be60e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +logs/ node_modules/ npm-debug.log diff --git a/config.js b/config.js index 1c4b0f54..6ec1ded8 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,7 @@ module.exports = { - password: "", port: 9000, + password: "", + log: true, theme: "", defaults: { nick: "shout-user", diff --git a/lib/models/chan.js b/lib/models/chan.js index 45145398..e78d7c2b 100644 --- a/lib/models/chan.js +++ b/lib/models/chan.js @@ -1,5 +1,7 @@ var _ = require("lodash"); var config = require("../../config") || {}; +var fs = require('fs'); +var moment = require("moment"); module.exports = Chan; @@ -16,11 +18,43 @@ function Chan(attr) { }; Chan.prototype.addMsg = function(msg) { - this.messages.push(msg); + this.messages.push(msg); + if (config.log != true || this.type == "lobby") { + return; + } + + var dir = "logs/"; + dir += this.network + "/"; + if (!fs.existsSync(dir)) { + fs.mkdir(dir); + console.log(dir); + } + + var date = moment().format("YYYY-MM-DD"); + var file = dir + this.name + ".log"; + + var line = "[" + msg.time + "] "; + if (msg.type == "normal") { + // Format: + // [00:00] Put that cookie down.. Now!! + line += "<" + msg.from + "> " + msg.text; + } else { + // Format: + // [00:00] * Arnold quit + line += "* " + msg.from + " " + msg.type; + if (msg.text) { + line += " " + msg.text; + } + } + + fs.appendFile( + file, + line + "\n" + ); }; Chan.prototype.addUser = function(user) { - this.users.push(user); + this.users.push(user); }; Chan.prototype.sortUsers = function() { diff --git a/lib/models/network.js b/lib/models/network.js index 07f179a0..428099cd 100644 --- a/lib/models/network.js +++ b/lib/models/network.js @@ -13,6 +13,8 @@ function Network(attr) { channels: [], }, attr)); + this.name = this.host.split(".")[1] || clone.host; + // Add lobby this.channels.unshift( new Chan({name: this.host, type: "lobby"}) @@ -20,7 +22,7 @@ function Network(attr) { }; Network.prototype.addChan = function(chan) { - chan.network = this.host; + chan.network = this.name; this.channels.push(chan); }; @@ -29,6 +31,5 @@ Network.prototype.toJSON = function() { "client", "connected", ]); - clone.name = clone.host.split(".")[1] || clone.host; return clone; };