about summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-09-30 19:21:34 -0400
committerJune McEnroe <june@causal.agency>2020-09-30 19:21:34 -0400
commitf3a56b0d014c96b3bbc41308d34f46a1f7b70764 (patch)
treed9da0df66a1fdc63f05fbcf7a8013aa5f6e2d04b /handle.c
parentAdd /ops command (diff)
downloadcatgirl-f3a56b0d014c96b3bbc41308d34f46a1f7b70764.tar.gz
catgirl-f3a56b0d014c96b3bbc41308d34f46a1f7b70764.zip
Use WHO for /ops
Accumulate names in a buffer and show away status.
Diffstat (limited to '')
-rw-r--r--handle.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/handle.c b/handle.c
index e3efe47..7519b87 100644
--- a/handle.c
+++ b/handle.c
@@ -499,26 +499,52 @@ static void handleReplyNames(struct Message *msg) {
 		char *user = strsep(&name, "@");
 		enum Color color = (user ? hash(user) : Default);
 		completeAdd(id, nick, color);
-		if (replies.ops && (prefixes == nick || prefixes[0] == '+')) continue;
-		if (!replies.ops && !replies.names) continue;
+		if (!replies.names) continue;
 		catf(&cat, "%s\3%02d%s\3", (buf[0] ? ", " : ""), color, prefixes);
 	}
 	if (!cat.len) return;
 	uiFormat(
 		id, Cold, tagTime(msg),
-		"%s \3%02d%s\3 are %s",
-		(replies.ops ? "The operators of" : "In"),
+		"In \3%02d%s\3 are %s",
 		hash(msg->params[2]), msg->params[2], buf
 	);
 }
 
 static void handleReplyEndOfNames(struct Message *msg) {
 	(void)msg;
-	if (replies.ops) {
-		replies.ops--;
-	} else if (replies.names) {
-		replies.names--;
+	if (replies.names) replies.names--;
+}
+
+static char whoBuf[1024];
+static struct Cat whoCat = { whoBuf, sizeof(whoBuf), 0 };
+
+static void handleReplyWho(struct Message *msg) {
+	require(msg, false, 7);
+	if (!replies.who) return;
+	if (!whoCat.len) {
+		catf(
+			&whoCat, "The operators of \3%02d%s\3 are ",
+			hash(msg->params[1]), msg->params[1]
+		);
 	}
+	char *prefixes = &msg->params[6][1];
+	if (prefixes[0] == '*') prefixes++;
+	prefixes[strspn(prefixes, network.prefixes)] = '\0';
+	if (!prefixes[0] || prefixes[0] == '+') return;
+	catf(
+		&whoCat, "%s\3%02d%s%s\3%s",
+		(whoCat.buf[whoCat.len - 1] == ' ' ? "" : ", "),
+		hash(msg->params[2]), prefixes, msg->params[5],
+		(msg->params[6][0] == 'H' ? "" : " (away)")
+	);
+}
+
+static void handleReplyEndOfWho(struct Message *msg) {
+	require(msg, false, 2);
+	if (!replies.who) return;
+	replies.who--;
+	uiWrite(idFor(msg->params[1]), Cold, tagTime(msg), whoBuf);
+	whoCat.len = 0;
 }
 
 static void handleReplyNoTopic(struct Message *msg) {
@@ -1196,6 +1222,7 @@ static const struct Handler {
 	{ "311", handleReplyWhoisUser },
 	{ "312", handleReplyWhoisServer },
 	{ "313", handleReplyWhoisGeneric },
+	{ "315", handleReplyEndOfWho },
 	{ "317", handleReplyWhoisIdle },
 	{ "318", handleReplyEndOfWhois },
 	{ "319", handleReplyWhoisChannels },
@@ -1210,6 +1237,7 @@ static const struct Handler {
 	{ "347", handleReplyEndOfInviteList },
 	{ "348", handleReplyExceptList },
 	{ "349", handleReplyEndOfExceptList },
+	{ "352", handleReplyWho },
 	{ "353", handleReplyNames },
 	{ "366", handleReplyEndOfNames },
 	{ "367", handleReplyBanList },
>Jason A. Donenfeld 2013-04-27t0001: validate Git -rcN version numbers correctlyJohn Keeping 2013-04-27git: update to 1.8.2.2John Keeping 2013-04-17scan-tree: fix regression in section-from-path=-1John Keeping 2013-04-15t0001: ignore ".dirty" suffix on Git versionJohn Keeping 2013-04-15tests: set TEST_OUTPUT_DIRECTORY to the CGit test directoryJohn Keeping 2013-04-15t0109: test more URLsJohn Keeping 2013-04-10cgitrc.5.txt: Specify when scan-path must be defined before.Jason A. Donenfeld 2013-04-10ui-snapshot.c: Prepend "V" when guessing ref namesLukas Fleischer 2013-04-10t0107: Skip ZIP tests if unzip(1) isn't availableLukas Fleischer 2013-04-10tests/: Do not use `sed -i`Lukas Fleischer 2013-04-10Add branch-sort and repo.branch-sort options.Jason A. Donenfeld 2013-04-10t0109: chain operations with &&John Keeping 2013-04-10cgit.c: Do not restore unset environment variablesLukas Fleischer 2013-04-09t0107: Use `tar -z` for gzip'ed archivesLukas Fleischer