about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-06 04:18:15 -0500
committerJune McEnroe <june@causal.agency>2020-02-06 04:18:15 -0500
commit32ec697092a8d9b4925e64519643c9005f2d408c (patch)
tree423bd31eecb2ad0f3828c0450dbda8acf9860ef2
parentRoute own query messages correctly (diff)
downloadcatgirl-32ec697092a8d9b4925e64519643c9005f2d408c.tar.gz
catgirl-32ec697092a8d9b4925e64519643c9005f2d408c.zip
Handle mentions
Diffstat (limited to '')
-rw-r--r--handle.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/handle.c b/handle.c
index 9244e66..01e2e5e 100644
--- a/handle.c
+++ b/handle.c
@@ -14,6 +14,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <ctype.h>
 #include <err.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -260,6 +261,21 @@ static bool isAction(struct Message *msg) {
 	return true;
 }
 
+static bool isMention(const struct Message *msg) {
+	if (!self.nick) return false;
+	size_t len = strlen(self.nick);
+	const char *match = msg->params[1];
+	while (NULL != (match = strcasestr(match, self.nick))) {
+		char a = (match > msg->params[1] ? match[-1] : ' ');
+		char b = (match[len] ? match[len] : ' ');
+		if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) {
+			return true;
+		}
+		match = &match[len];
+	}
+	return false;
+}
+
 static void handlePrivmsg(struct Message *msg) {
 	require(msg, true, 2);
 	bool query = !strchr(self.chanTypes, msg->params[0][0]);
@@ -277,9 +293,11 @@ static void handlePrivmsg(struct Message *msg) {
 
 	bool notice = (msg->cmd[0] == 'N');
 	bool action = isAction(msg);
+	bool mention = !mine && isMention(msg);
 	uiFormat(
-		id, Warm, tagTime(msg),
-		"\3%d%s%s%s\3\t%s",
+		id, (mention || query ? Hot : Warm), tagTime(msg),
+		"%s\3%d%s%s%s\17\t%s",
+		(mention ? "\26" : ""),
 		hash(msg->user),
 		(action ? "* " : notice ? "-" : "<"),
 		msg->nick,