diff --git a/components/app.js b/components/app.js index 307c1f7..cc77b70 100644 --- a/components/app.js +++ b/components/app.js @@ -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; diff --git a/components/buffer.js b/components/buffer.js index d54ba0b..1924e5f 100644 --- a/components/buffer.js +++ b/components/buffer.js @@ -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))}`; diff --git a/lib/irc.js b/lib/irc.js index 88edbdb..0d8ceb7 100644 --- a/lib/irc.js +++ b/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; +}