Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/parse_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion test/data/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down