diff options
author | June McEnroe | 2022-05-29 18:09:52 -0400 |
---|---|---|
committer | June McEnroe | 2022-05-29 18:09:52 -0400 |
commit | 3475f03ec8c9ee26544c17b5f3d1cba7b1104f5e (patch) | |
tree | 51a7b2881e54369316856602f297827803a4ad53 /handle.c | |
parent | a5162d83bd0f91ee41292798743042606428bfb0 (diff) |
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.
Diffstat (limited to 'handle.c')
-rw-r--r-- | handle.c | 25 |
1 files changed, 19 insertions, 6 deletions
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'; |