Parse all CTCP messages

We display them nicely, however we never reply to them.
This commit is contained in:
Simon Ser 2020-08-13 16:04:39 +02:00
parent 012b9f515a
commit bce216b7fb
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 36 additions and 7 deletions

View file

@ -304,7 +304,7 @@ export default class App extends Component {
msgUnread = Unread.MESSAGE;
}
if (msgUnread == Unread.HIGHLIGHT && window.Notification && Notification.permission === "granted" && !isDelivered) {
if (msgUnread == Unread.HIGHLIGHT && window.Notification && Notification.permission === "granted" && !isDelivered && !irc.parseCTCP(msg)) {
var title = "New " + kind + " from " + msg.prefix.name;
if (this.isChannel(target)) {
title += " in " + target;

View file

@ -60,12 +60,16 @@ class LogLine extends Component {
case "PRIVMSG":
var text = msg.params[1];
var actionPrefix = "\x01ACTION ";
if (text.startsWith(actionPrefix) && text.endsWith("\x01")) {
var action = text.slice(actionPrefix.length, -1);
lineClass = "me-tell";
content = html`* ${createNick(msg.prefix.name)} ${linkify(stripANSI(action))}`;
var ctcp = irc.parseCTCP(msg);
if (ctcp) {
if (ctcp.command == "ACTION") {
lineClass = "me-tell";
content = html`* ${createNick(msg.prefix.name)} ${linkify(stripANSI(ctcp.param))}`;
} else {
content = html`
${createNick(msg.prefix.name)} has sent a CTCP command: ${ctcp.command} ${ctcp.param}
`;
}
} else {
lineClass = "talk";
content = html`${"<"}${createNick(msg.prefix.name)}${">"} ${linkify(stripANSI(text))}`;

View file

@ -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;
}