Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed May 15, 2023
1 parent 79cb54e commit d524393
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/105.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for [message tags](https://ircv3.net/specs/extensions/message-tags).
24 changes: 23 additions & 1 deletion src/parse_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,29 @@ export function parseMessage(line: string, opts: Partial<ParserOptions>|boolean
message.tags = new Map(
// Strip @
tags.substring(1).trim().split(';').map(
(tag) => tag.split('=', 2)
(tag) => {
const parts = tag.split('=');
return [
parts.splice(0, 1)[0],
parts.join('=').replace(/\\(s|\\|r|n|:)/g, (char) => {
// https://ircv3.net/specs/extensions/message-tags#escaping-values
switch (char) {
case "\\s":
return " ";
case "\\r":
return "\r";
case "\\n":
return "\n";
case "\\\\":
return '\\';
case "\\:":
return ';';
default:
return char;
}
}),
]
}
) as Array<[string, string|undefined]>
);
}
Expand Down
37 changes: 32 additions & 5 deletions test/data/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@
},
"@msgid=63E1033A051D4B41B1AB1FA3CF4B243E :nick!user@host PRIVMSG #channel :Hello!": {
"opts": {
"supportsMessageTags": true,
"stripColors": false
"supportsMessageTags": true
},
"prefix": "nick!user@host",
"nick": "nick",
Expand All @@ -141,9 +140,37 @@
"tags": [ [ "msgid", "63E1033A051D4B41B1AB1FA3CF4B243E" ] ],
"args": ["#channel", "Hello!"]
},
":pratchett.freenode.net 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
"prefix": "pratchett.freenode.net",
"server": "pratchett.freenode.net",
"@+example=raw+:=,escaped\\:\\s\\\\ :nick!user@example.com PRIVMSG #channel :Message": {
"opts": {
"supportsMessageTags": true
},
"user": "user",
"nick": "nick",
"prefix": "nick!user@example.com",
"host": "example.com",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"tags": [ [ "+example", "raw+:=,escaped; \\" ] ],
"args": ["#channel", "Message"]
},
"@label=123;msgid=abc;+example-client-tag=example-value :nick!user@example.com TAGMSG #channel": {
"opts": {
"supportsMessageTags": true
},
"prefix": "nick!user@example.com",
"nick": "nick",
"user": "user",
"host": "example.com",
"command": "TAGMSG",
"rawCommand": "TAGMSG",
"commandType": "normal",
"tags":[ [ "label", "123" ], [ "msgid", "abc" ], [ "+example-client-tag", "example-value" ] ],
"args": ["#channel"]
},
":host.foo.bar 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
"prefix": "host.foo.bar",
"server": "host.foo.bar",
"command": "rpl_channelmodeis",
"rawCommand": "324",
"commandType": "reply",
Expand Down

0 comments on commit d524393

Please sign in to comment.