Parse all CTCP messages
We display them nicely, however we never reply to them.
This commit is contained in:
parent
012b9f515a
commit
bce216b7fb
3 changed files with 36 additions and 7 deletions
25
lib/irc.js
25
lib/irc.js
|
@ -279,3 +279,28 @@ export function formatDate(date) {
|
|||
var sss = date.getUTCMilliseconds().toString().padStart(3, "0");
|
||||
return `${YYYY}-${MM}-${DD}T${hh}:${mm}:${ss}.${sss}Z`;
|
||||
}
|
||||
|
||||
export function parseCTCP(msg) {
|
||||
if (msg.command != "PRIVMSG" && msg.command != "NOTICE") {
|
||||
return null;
|
||||
}
|
||||
|
||||
var text = msg.params[1];
|
||||
if (!text.startsWith("\x01")) {
|
||||
return null;
|
||||
}
|
||||
text = text.slice(1);
|
||||
if (text.endsWith("\x01")) {
|
||||
text = text.slice(0, -1);
|
||||
}
|
||||
|
||||
var ctcp;
|
||||
var i = text.indexOf(" ");
|
||||
if (i >= 0) {
|
||||
ctcp = { command: text.slice(0, i), param: text.slice(i + 1) };
|
||||
} else {
|
||||
ctcp = { command: text, param: "" };
|
||||
}
|
||||
ctcp.command = ctcp.command.toUpperCase();
|
||||
return ctcp;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue