Skip to content

Commit

Permalink
Merge pull request #306 from martynsmith/apeiron/use-irc-colors
Browse files Browse the repository at this point in the history
Bring in irc-colors for stripping colors
  • Loading branch information
jirwin committed Jan 14, 2015
2 parents 4d22148 + 77bfad4 commit 98f2bd0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/parse_message.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var ircColors = require('irc-colors');
var replyFor = require('./codes');

/**
Expand All @@ -14,7 +15,7 @@ module.exports = function parseMessage(line, stripColors) {
var match;

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

// Parse prefix
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
}
],
"dependencies": {
"ansi-color": "0.2.1"
"ansi-color": "0.2.1",
"irc-colors": "^1.1.0"
},
"optionalDependencies": {
"iconv": "~2.1.4",
Expand Down
22 changes: 22 additions & 0 deletions test/data/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@
"commandType": "normal",
"args": ["#channel", "so : colons: :are :: not a problem ::::"]
},
":nick!user@host PRIVMSG #channel :\u000314,01\u001fneither are colors or styles\u001f\u0003": {
"prefix": "nick!user@host",
"nick": "nick",
"user": "user",
"host": "host",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#channel", "neither are colors or styles"],
"stripColors": true
},
":nick!user@host PRIVMSG #channel :\u000314,01\u001fwe can leave styles and colors alone if desired\u001f\u0003": {
"prefix": "nick!user@host",
"nick": "nick",
"user": "user",
"host": "host",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#channel", "\u000314,01\u001fwe can leave styles and colors alone if desired\u001f\u0003"],
"stripColors": false
},
":pratchett.freenode.net 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
"prefix": "pratchett.freenode.net",
"server": "pratchett.freenode.net",
Expand Down
7 changes: 6 additions & 1 deletion test/test-parse-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ test('irc.parseMessage', function(t) {
var checks = testHelpers.getFixtures('parse-line');

Object.keys(checks).forEach(function(line) {
var stripColors = false;
if (checks[line].hasOwnProperty('stripColors')) {
stripColors = checks[line].stripColors;
delete checks[line].stripColors;
}
t.equal(
JSON.stringify(checks[line]),
JSON.stringify(parseMessage(line)),
JSON.stringify(parseMessage(line, stripColors)),
line + ' parses correctly'
);
});
Expand Down

0 comments on commit 98f2bd0

Please sign in to comment.