From 3475f03ec8c9ee26544c17b5f3d1cba7b1104f5e Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 29 May 2022 18:09:52 -0400 Subject: Allow setting fallback nicks and highlight on any As a side-effect, even with only one nick set you'll still be highlighted by it even if your current nick is different. --- handle.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'handle.c') diff --git a/handle.c b/handle.c index f51323d..e4fe0ab 100644 --- a/handle.c +++ b/handle.c @@ -148,7 +148,12 @@ static void handleReplyGeneric(struct Message *msg) { static void handleErrorNicknameInUse(struct Message *msg) { require(msg, false, 2); if (!strcmp(self.nick, "*")) { - ircFormat("NICK :%s_\r\n", msg->params[1]); + static uint i = 1; + if (i < ARRAY_LEN(self.nicks) && self.nicks[i]) { + ircFormat("NICK %s\r\n", self.nicks[i++]); + } else { + ircFormat("NICK %s_\r\n", msg->params[1]); + } } else { handleErrorGeneric(msg); } @@ -1207,11 +1212,11 @@ static bool isAction(struct Message *msg) { return true; } -static bool isMention(const struct Message *msg) { - size_t len = strlen(self.nick); - const char *match = msg->params[1]; - while (NULL != (match = strstr(match, self.nick))) { - char a = (match > msg->params[1] ? match[-1] : ' '); +static bool matchWord(const char *str, const char *word) { + size_t len = strlen(word); + const char *match = str; + while (NULL != (match = strstr(match, word))) { + char a = (match > str ? match[-1] : ' '); char b = (match[len] ?: ' '); if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) { return true; @@ -1221,6 +1226,14 @@ static bool isMention(const struct Message *msg) { return false; } +static bool isMention(const struct Message *msg) { + if (matchWord(msg->params[1], self.nick)) return true; + for (uint i = 0; i < ARRAY_LEN(self.nicks) && self.nicks[i]; ++i) { + if (matchWord(msg->params[1], self.nicks[i])) return true; + } + return false; +} + static void colorMentions(char *buf, size_t cap, uint id, struct Message *msg) { *buf = '\0'; -- cgit 1.4.1-2-gfad0