Skip to content

Commit

Permalink
Add stripColors option to remove mirc colors and ircII formatting (bo…
Browse files Browse the repository at this point in the history
…ld, underline, reverse) in order to make bots easier to write.
  • Loading branch information
Excedrin committed Oct 27, 2011
1 parent b927d21 commit 91c022b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ function Client(server, nick, opt) {
retryDelay: 2000,
secure: false,
selfSigned: false,
floodProtection: false
floodProtection: false,
stripColors: false
};

if (typeof arguments[2] == 'object') {
Expand Down Expand Up @@ -905,7 +906,7 @@ Client.prototype.connect = function ( retryCount ) { // {{{
var lines = buffer.split("\r\n");
buffer = lines.pop();
lines.forEach(function (line) {
var message = parseMessage(line);
var message = parseMessage(line, self.opt.stripColors);
try {
self.emit('raw', message);
} catch ( err ) {
Expand Down Expand Up @@ -1076,15 +1077,22 @@ Client.prototype._clearWhoisData = function(nick) { // {{{
} // }}}

/*
* parseMessage(line)
* parseMessage(line, stripColors)
*
* takes a raw "line" from the IRC server and turns it into an object with
* useful keys
*/
function parseMessage(line) { // {{{
function parseMessage(rawLine, stripColors) { // {{{
var message = {};
var match;

var line;
if (stripColors) {
line = rawLine.replace(/[\x02\x1f\x16\x0f]|\x03\d{0,2}(?:,\d{0,2})?/g, "");
} else {
line = rawLine;
}

// Parse prefix
if ( match = line.match(/^:([^ ]+) +/) ) {
message.prefix = match[1];
Expand Down

0 comments on commit 91c022b

Please sign in to comment.