Commits

wifiman  committed ac9d3bd

Added buffering and config.log support for IRC writes.

  • Participants
  • Parent commits 334bf5b

Comments (0)

Files changed (1)

File desktopbot.js

 var ircConn = net.connect(config.serverPort, config.server, function () {
 	this.setEncoding('utf8');
 
+	this.realWrite = this.write;
+	var writeBuffer = '';
+	this.write = function (message) {
+		var lines = (writeBuffer + message).split(/\r\n/);
+		writeBuffer = lines.pop();
+
+		if (config.log)
+			for (var i = 0; i < lines.length; ++i)
+				config.log(true, lines[i])
+
+		if (lines.length > 0)
+			this.realWrite(lines.join('\r\n') + '\r\n');
+	}
+
 	var output = 'NICK ' + config.nick + '\r\n'
 	           + 'USER ' + config.nick + ' localhost localhost :' + config.nick + '\r\n';