about summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-11-29 05:37:10 -0500
committerJune McEnroe <june@causal.agency>2018-11-29 05:40:26 -0500
commite4eb97e5126d5f100ac29a34e43afa6fb9f663e2 (patch)
treea335c82a326bad9aa33a6425c96cdd50539b7c5f /handle.c
parentSet LIBRESSL_PREFIX in Darwin.mk (diff)
downloadcatgirl-e4eb97e5126d5f100ac29a34e43afa6fb9f663e2.tar.gz
catgirl-e4eb97e5126d5f100ac29a34e43afa6fb9f663e2.zip
Add /whois
Diffstat (limited to '')
-rw-r--r--handle.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/handle.c b/handle.c
index 05e94e4..35c1e5f 100644
--- a/handle.c
+++ b/handle.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
+#include <time.h>
 
 #include "chat.h"
 
@@ -129,6 +130,58 @@ static void handleReplyMOTD(char *prefix, char *params) {
 	uiFmt(TagStatus, UICold, "%s", mesg);
 }
 
+static enum IRCColor whoisColor;
+static void handleReplyWhoisUser(char *prefix, char *params) {
+	char *nick, *user, *host, *real;
+	shift(
+		prefix, NULL, NULL, NULL,
+		params, 6, 0, NULL, &nick, &user, &host, NULL, &real
+	);
+	whoisColor = formatColor(user);
+	uiFmt(
+		TagStatus, UIWarm,
+		"\3%d%s\3 is %s@%s \"%s\"",
+		whoisColor, nick, user, host, real
+	);
+}
+
+static void handleReplyWhoisServer(char *prefix, char *params) {
+	char *nick, *serv, *info;
+	shift(prefix, NULL, NULL, NULL, params, 4, 0, NULL, &nick, &serv, &info);
+	uiFmt(
+		TagStatus, UIWarm,
+		"\3%d%s\3 is connected to %s, \"%s\"",
+		whoisColor, nick, serv, info
+	);
+}
+
+static void handleReplyWhoisOperator(char *prefix, char *params) {
+	char *nick, *oper;
+	shift(prefix, NULL, NULL, NULL, params, 3, 0, NULL, &nick, &oper);
+	uiFmt(TagStatus, UIWarm, "\3%d%s\3 %s", whoisColor, nick, oper);
+}
+
+static void handleReplyWhoisIdle(char *prefix, char *params) {
+	char *nick, *idle, *sign;
+	shift(prefix, NULL, NULL, NULL, params, 4, 0, NULL, &nick, &idle, &sign);
+	time_t time = strtoul(sign, NULL, 10);
+	const char *at = ctime(&time);
+	unsigned long secs  = strtoul(idle, NULL, 10);
+	unsigned long mins  = secs / 60; secs %= 60;
+	unsigned long hours = mins / 60; mins %= 60;
+	uiFmt(
+		TagStatus, UIWarm,
+		"\3%d%s\3 signed on at %.24s and has been idle for %02lu:%02lu:%02lu",
+		whoisColor, nick, at, hours, mins, secs
+	);
+}
+
+static void handleReplyWhoisChannels(char *prefix, char *params) {
+	char *nick, *chans;
+	shift(prefix, NULL, NULL, NULL, params, 3, 0, NULL, &nick, &chans);
+	uiFmt(TagStatus, UIWarm, "\3%d%s\3 is in %s", whoisColor, nick, chans);
+}
+
 static void handleJoin(char *prefix, char *params) {
 	char *nick, *user, *chan;
 	shift(prefix, &nick, &user, NULL, params, 1, 0, &chan);
@@ -400,7 +453,12 @@ static const struct {
 	Handler handler;
 } Handlers[] = {
 	{ "001", handleReplyWelcome },
+	{ "311", handleReplyWhoisUser },
+	{ "312", handleReplyWhoisServer },
+	{ "313", handleReplyWhoisOperator },
 	{ "315", handleReplyEndOfWho },
+	{ "317", handleReplyWhoisIdle },
+	{ "319", handleReplyWhoisChannels },
 	{ "332", handleReplyTopic },
 	{ "352", handleReplyWho },
 	{ "366", handleReplyEndOfNames },