Skip to content

Commit

Permalink
Merged PR 81
Browse files Browse the repository at this point in the history
  • Loading branch information
aabluedragon authored Sep 30, 2024
1 parent 620c112 commit 33b402d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/parse_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ export function parseMessage(line: string, stripColors: boolean): Message {
}

// Parse prefix
// Merged PR https://github.com/matrix-org/node-irc/pull/81
let match = line.match(/^:([^ ]+) +/);
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

0 comments on commit 33b402d

Please sign in to comment.