summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-09-11 17:34:41 -0400
committerJune McEnroe <june@causal.agency>2022-09-11 17:34:41 -0400
commitfcbe7af1e2ac2abb71251a51f5384d22cad9a87a (patch)
treee5583b434defc629f35cf286f69413a1787a610e
parentSet pointer to Entry in Cursor (diff)
downloadcatgirl-fcbe7af1e2ac2abb71251a51f5384d22cad9a87a.tar.gz
catgirl-fcbe7af1e2ac2abb71251a51f5384d22cad9a87a.zip
Generate /ops from cache
-rw-r--r--chat.h13
-rw-r--r--command.c27
-rw-r--r--handle.c6
3 files changed, 38 insertions, 8 deletions
diff --git a/chat.h b/chat.h
index c7053c7..198b84e 100644
--- a/chat.h
+++ b/chat.h
@@ -168,6 +168,19 @@ extern struct Network {
 	char invex;
 } network;
 
+static inline uint prefixBit(char p) {
+	char *s = strchr(network.prefixes, p);
+	if (!s) return 0;
+	return 1 << (s - network.prefixes);
+}
+
+static inline char bitPrefix(uint p) {
+	for (uint i = 0; network.prefixes[i]; ++i) {
+		if (p & (1 << i)) return network.prefixes[i];
+	}
+	return '\0';
+}
+
 #define ENUM_CAP \
 	X("causal.agency/consumer", CapConsumer) \
 	X("chghost", CapChghost) \
diff --git a/command.c b/command.c
index 3acbe76..4fb58da 100644
--- a/command.c
+++ b/command.c
@@ -219,8 +219,31 @@ static void commandNames(uint id, char *params) {
 
 static void commandOps(uint id, char *params) {
 	(void)params;
-	ircFormat("WHO %s\r\n", idNames[id]);
-	replies[ReplyWho]++;
+	char buf[1024];
+	char *ptr = buf, *end = &buf[sizeof(buf)];
+	ptr = seprintf(
+		ptr, end, "The council of \3%02d%s\3 are ",
+		idColors[id], idNames[id]
+	);
+	bool first = true;
+	struct Cursor curs = {0};
+	for (const char *nick; (nick = cacheNextKey(&curs, id));) {
+		char prefix = bitPrefix(curs.entry->prefixBits);
+		if (!prefix || prefix == '+') continue;
+		ptr = seprintf(
+			ptr, end, "%s\3%02d%c%s\3",
+			(first ? "" : ", "), curs.entry->color, prefix, nick
+		);
+		first = false;
+	}
+	if (first) {
+		uiFormat(
+			id, Warm, NULL, "\3%02d%s\3 is a lawless wasteland",
+			idColors[id], idNames[id]
+		);
+	} else {
+		uiWrite(id, Warm, NULL, buf);
+	}
 }
 
 static void commandInvite(uint id, char *params) {
diff --git a/handle.c b/handle.c
index a075d02..cebc7e4 100644
--- a/handle.c
+++ b/handle.c
@@ -560,12 +560,6 @@ static void handleErrorUserOnChannel(struct Message *msg) {
 	);
 }
 
-static uint prefixBit(char p) {
-	char *s = strchr(network.prefixes, p);
-	if (!s) return 0;
-	return 1 << (s - network.prefixes);
-}
-
 static void handleReplyNames(struct Message *msg) {
 	require(msg, false, 4);
 	uint id = idFor(msg->params[2]);