summary refs log tree commit diff
path: root/filter.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-05-04 15:34:27 -0400
committerJune McEnroe <june@causal.agency>2021-05-04 15:34:27 -0400
commit6207aaf1a87f3f1ecfb46ad6b0288db94fc6329e (patch)
treee1f77ed10140038af243266dd7ff316a87eed7a7 /filter.c
parentAdd support for BINDIR, fix default MANDIR, use LDADD vars (diff)
downloadcatgirl-6207aaf1a87f3f1ecfb46ad6b0288db94fc6329e.tar.gz
catgirl-6207aaf1a87f3f1ecfb46ad6b0288db94fc6329e.zip
Ignore messages in reply to previously ignored messages
Using the +draft/reply client tag, which is supported by BitBot.
This hides the bot's replies to ignored users or ignored bot command
messages.

This commit is dedicated to the land of Estonia.
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/filter.c b/filter.c
index a648d8b..63c3369 100644
--- a/filter.c
+++ b/filter.c
@@ -94,12 +94,39 @@ static bool filterTest(
 	return !fnmatch(filter.mesg, msg->params[1], FNM_CASEFOLD);
 }
 
+enum { IcedCap = 8 };
+static struct {
+	size_t len;
+	char *msgIDs[IcedCap];
+} iced;
+
+static void icedPush(const char *msgID) {
+	if (!msgID) return;
+	size_t i = iced.len % IcedCap;
+	free(iced.msgIDs[i]);
+	iced.msgIDs[i] = strdup(msgID);
+	if (!iced.msgIDs[i]) err(EX_OSERR, "strdup");
+	iced.len++;
+}
+
 enum Heat filterCheck(enum Heat heat, uint id, const struct Message *msg) {
 	if (!len) return heat;
+
+	if (msg->tags[TagReply]) {
+		for (size_t i = 0; i < IcedCap; ++i) {
+			if (!iced.msgIDs[i]) continue;
+			if (strcmp(msg->tags[TagReply], iced.msgIDs[i])) continue;
+			icedPush(msg->tags[TagMsgID]);
+			return Ice;
+		}
+	}
+
 	char mask[512];
 	snprintf(mask, sizeof(mask), "%s!%s@%s", msg->nick, msg->user, msg->host);
 	for (size_t i = 0; i < len; ++i) {
-		if (filterTest(filters[i], mask, id, msg)) return filters[i].heat;
+		if (!filterTest(filters[i], mask, id, msg)) continue;
+		if (filters[i].heat == Ice) icedPush(msg->tags[TagMsgID]);
+		return filters[i].heat;
 	}
 	return heat;
 }