about summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-05-29 18:09:52 -0400
committerJune McEnroe <june@causal.agency>2022-05-29 18:09:52 -0400
commit3475f03ec8c9ee26544c17b5f3d1cba7b1104f5e (patch)
tree51a7b2881e54369316856602f297827803a4ad53 /handle.c
parentDocument visibility of unknown replies (diff)
downloadcatgirl-3475f03ec8c9ee26544c17b5f3d1cba7b1104f5e.tar.gz
catgirl-3475f03ec8c9ee26544c17b5f3d1cba7b1104f5e.zip
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 '')
-rw-r--r--handle.c25
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';