Skip to content

Commit d524393

Browse files
committed
changelog
1 parent 79cb54e commit d524393

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

changelog.d/105.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for [message tags](https://ircv3.net/specs/extensions/message-tags).

src/parse_message.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,29 @@ export function parseMessage(line: string, opts: Partial<ParserOptions>|boolean
8080
message.tags = new Map(
8181
// Strip @
8282
tags.substring(1).trim().split(';').map(
83-
(tag) => tag.split('=', 2)
83+
(tag) => {
84+
const parts = tag.split('=');
85+
return [
86+
parts.splice(0, 1)[0],
87+
parts.join('=').replace(/\\(s|\\|r|n|:)/g, (char) => {
88+
// https://ircv3.net/specs/extensions/message-tags#escaping-values
89+
switch (char) {
90+
case "\\s":
91+
return " ";
92+
case "\\r":
93+
return "\r";
94+
case "\\n":
95+
return "\n";
96+
case "\\\\":
97+
return '\\';
98+
case "\\:":
99+
return ';';
100+
default:
101+
return char;
102+
}
103+
}),
104+
]
105+
}
84106
) as Array<[string, string|undefined]>
85107
);
86108
}

test/data/fixtures.json

+32-5
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@
128128
},
129129
"@msgid=63E1033A051D4B41B1AB1FA3CF4B243E :nick!user@host PRIVMSG #channel :Hello!": {
130130
"opts": {
131-
"supportsMessageTags": true,
132-
"stripColors": false
131+
"supportsMessageTags": true
133132
},
134133
"prefix": "nick!user@host",
135134
"nick": "nick",
@@ -141,9 +140,37 @@
141140
"tags": [ [ "msgid", "63E1033A051D4B41B1AB1FA3CF4B243E" ] ],
142141
"args": ["#channel", "Hello!"]
143142
},
144-
":pratchett.freenode.net 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
145-
"prefix": "pratchett.freenode.net",
146-
"server": "pratchett.freenode.net",
143+
"@+example=raw+:=,escaped\\:\\s\\\\ :[email protected] PRIVMSG #channel :Message": {
144+
"opts": {
145+
"supportsMessageTags": true
146+
},
147+
"user": "user",
148+
"nick": "nick",
149+
"prefix": "[email protected]",
150+
"host": "example.com",
151+
"command": "PRIVMSG",
152+
"rawCommand": "PRIVMSG",
153+
"commandType": "normal",
154+
"tags": [ [ "+example", "raw+:=,escaped; \\" ] ],
155+
"args": ["#channel", "Message"]
156+
},
157+
"@label=123;msgid=abc;+example-client-tag=example-value :[email protected] TAGMSG #channel": {
158+
"opts": {
159+
"supportsMessageTags": true
160+
},
161+
"prefix": "[email protected]",
162+
"nick": "nick",
163+
"user": "user",
164+
"host": "example.com",
165+
"command": "TAGMSG",
166+
"rawCommand": "TAGMSG",
167+
"commandType": "normal",
168+
"tags":[ [ "label", "123" ], [ "msgid", "abc" ], [ "+example-client-tag", "example-value" ] ],
169+
"args": ["#channel"]
170+
},
171+
":host.foo.bar 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
172+
"prefix": "host.foo.bar",
173+
"server": "host.foo.bar",
147174
"command": "rpl_channelmodeis",
148175
"rawCommand": "324",
149176
"commandType": "reply",

0 commit comments

Comments
 (0)