about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-08 03:15:17 -0500
committerJune McEnroe <june@causal.agency>2020-02-08 03:15:17 -0500
commitb6bf6d62b0bb6d203ce41e4b375c415ca8fde719 (patch)
tree8ef0a65fc49fce6d40ce8e1aff552c25a88f20b5
parentAdd /debug (diff)
downloadcatgirl-b6bf6d62b0bb6d203ce41e4b375c415ca8fde719.tar.gz
catgirl-b6bf6d62b0bb6d203ce41e4b375c415ca8fde719.zip
Only show expected topic/names replies
Diffstat (limited to '')
-rw-r--r--chat.h5
-rw-r--r--command.c8
-rw-r--r--handle.c23
3 files changed, 35 insertions, 1 deletions
diff --git a/chat.h b/chat.h
index 9daa38c..34e1812 100644
--- a/chat.h
+++ b/chat.h
@@ -114,6 +114,11 @@ void ircSend(const char *ptr, size_t len);
 void ircFormat(const char *format, ...)
 	__attribute__((format(printf, 1, 2)));
 
+extern struct Replies {
+	size_t topic;
+	size_t names;
+} replies;
+
 void handle(struct Message msg);
 void command(size_t id, char *input);
 const char *commandIsPrivmsg(size_t id, const char *input);
diff --git a/command.c b/command.c
index 1d1c756..9879dbe 100644
--- a/command.c
+++ b/command.c
@@ -71,7 +71,15 @@ static void commandMe(size_t id, char *params) {
 }
 
 static void commandJoin(size_t id, char *params) {
+	size_t count = 1;
+	if (params) {
+		for (char *ch = params; *ch && *ch != ' '; ++ch) {
+			if (*ch == ',') count++;
+		}
+	}
 	ircFormat("JOIN %s\r\n", (params ? params : idNames[id]));
+	replies.topic += count;
+	replies.names += count;
 }
 
 static void commandPart(size_t id, char *params) {
diff --git a/handle.c b/handle.c
index 8ebc3b1..0780767 100644
--- a/handle.c
+++ b/handle.c
@@ -25,6 +25,8 @@
 
 #include "chat.h"
 
+struct Replies replies;
+
 static const char *CapNames[] = {
 #define X(name, id) [id##Bit] = name,
 	ENUM_CAP
@@ -156,7 +158,15 @@ static void handleReplyWelcome(struct Message *msg) {
 	require(msg, false, 1);
 	set(&self.nick, msg->params[0]);
 	completeTouch(None, self.nick, Default);
-	if (self.join) ircFormat("JOIN %s\r\n", self.join);
+	if (self.join) {
+		size_t count = 1;
+		for (const char *ch = self.join; *ch && *ch != ' '; ++ch) {
+			if (*ch == ',') count++;
+		}
+		ircFormat("JOIN %s\r\n", self.join);
+		replies.topic += count;
+		replies.names += count;
+	}
 }
 
 static void handleReplyISupport(struct Message *msg) {
@@ -278,6 +288,7 @@ static void handleQuit(struct Message *msg) {
 
 static void handleReplyNames(struct Message *msg) {
 	require(msg, false, 4);
+	if (!replies.names) return;
 	size_t id = idFor(msg->params[2]);
 	char buf[1024];
 	size_t len = 0;
@@ -302,8 +313,15 @@ static void handleReplyNames(struct Message *msg) {
 	);
 }
 
+static void handleReplyEndOfNames(struct Message *msg) {
+	(void)msg;
+	if (replies.names) replies.names--;
+}
+
 static void handleReplyNoTopic(struct Message *msg) {
 	require(msg, false, 2);
+	if (!replies.topic) return;
+	replies.topic--;
 	uiFormat(
 		idFor(msg->params[1]), Cold, tagTime(msg),
 		"There is no sign in \3%02d%s\3",
@@ -313,6 +331,8 @@ static void handleReplyNoTopic(struct Message *msg) {
 
 static void handleReplyTopic(struct Message *msg) {
 	require(msg, false, 3);
+	if (!replies.topic) return;
+	replies.topic--;
 	uiFormat(
 		idFor(msg->params[1]), Cold, tagTime(msg),
 		"The sign in \3%02d%s\3 reads: %s",
@@ -421,6 +441,7 @@ static const struct Handler {
 	{ "331", handleReplyNoTopic },
 	{ "332", handleReplyTopic },
 	{ "353", handleReplyNames },
+	{ "366", handleReplyEndOfNames },
 	{ "372", handleReplyMOTD },
 	{ "432", handleErrorErroneousNickname },
 	{ "433", handleErrorNicknameInUse },