From 32ec697092a8d9b4925e64519643c9005f2d408c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 6 Feb 2020 04:18:15 -0500 Subject: [PATCH] Handle mentions --- handle.c | 22 ++++++++++++++++++++-- 1 file 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 . */ +#include #include #include #include @@ -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,