diff --git a/src/parse_message.ts b/src/parse_message.ts index 8c730f98..87bd0af2 100644 --- a/src/parse_message.ts +++ b/src/parse_message.ts @@ -37,11 +37,18 @@ export function parseMessage(line: string, stripColors: boolean): Message { if (match) { message.prefix = match[1]; line = line.replace(/^:[^ ]+ +/, ''); - match = message.prefix.match(/^([_a-zA-Z0-9\[\]\\`^{}|-]*)(!([^@]+)@(.*))?$/); - if (match) { - message.nick = match[1]; - message.user = match[3]; - message.host = match[4]; + const userDelim = message.prefix.indexOf('!'); + const hostDelim = message.prefix.indexOf('@'); + if (userDelim !== -1 && hostDelim !== -1) { + message.nick = message.prefix.substring(0, userDelim); + message.user = message.prefix.substring(userDelim+1, hostDelim); + message.host = message.prefix.substring(hostDelim+1); + } + else if (userDelim === -1 && hostDelim !== -1) { + // I don't think we'll get here, but we could if someone sends user@server + message.nick = message.prefix.substring(0, hostDelim); + message.user = undefined; + message.host = message.prefix.substring(hostDelim+1); } else { message.server = message.prefix; diff --git a/test/data/fixtures.json b/test/data/fixtures.json index b6fc871a..1f0d3350 100644 --- a/test/data/fixtures.json +++ b/test/data/fixtures.json @@ -129,8 +129,18 @@ "rawCommand": "324", "commandType": "reply", "args": ["nodebot", "#ubuntu", "+CLcntjf", "5:10", "#ubuntu-unregged"] + }, + ":emerson/matrix!~u@znkrci9cjw8y2.irc PRIVMSG #relaymsg-testing :testing relaymsg2": { + "prefix": "emerson/matrix!~u@znkrci9cjw8y2.irc", + "nick": "emerson/matrix", + "user": "~u", + "host": "znkrci9cjw8y2.irc", + "command": "PRIVMSG", + "rawCommand": "PRIVMSG", + "commandType": "normal", + "args": ["#relaymsg-testing", "testing relaymsg2"], + "stripColors": false } - }, "433-before-001": { "sent": [