mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
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
|
@ -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;
|
||||
|
|
|
@ -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))}`;
|
||||
|
|
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…
Reference in a new issue