summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--catgirl.13
-rw-r--r--handle.c58
-rw-r--r--input.c12
3 files changed, 71 insertions, 2 deletions
diff --git a/catgirl.1 b/catgirl.1
index 2ffd7d0..55220a1 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -185,6 +185,9 @@ Switch to view for
 .
 .It Ic /who
 List users in the current channel.
+.
+.It Ic /whois Ar nick
+Query information about a user.
 .El
 .
 .Pp
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 },
diff --git a/input.c b/input.c
index 3a3d499..85c240f 100644
--- a/input.c
+++ b/input.c
@@ -87,6 +87,13 @@ static void inputWho(struct Tag tag, char *params) {
 	ircFmt("WHO %s\r\n", tag.name);
 }
 
+static void inputWhois(struct Tag tag, char *params) {
+	(void)tag;
+	char *nick = param("/whois", &params, "nick");
+	if (!nick) return;
+	ircFmt("WHOIS %s\r\n", nick);
+}
+
 static void inputTopic(struct Tag tag, char *params) {
 	if (params) {
 		ircFmt("TOPIC %s :%s\r\n", tag.name, params);
@@ -104,7 +111,7 @@ static void inputQuit(struct Tag tag, char *params) {
 	}
 }
 
-static void inputUrl(struct Tag tag, char *params) {
+static void inputURL(struct Tag tag, char *params) {
 	(void)params;
 	urlList(tag);
 }
@@ -163,9 +170,10 @@ static const struct {
 	{ "/query", inputQuery },
 	{ "/quit", inputQuit },
 	{ "/topic", inputTopic },
-	{ "/url", inputUrl },
+	{ "/url", inputURL },
 	{ "/view", inputView },
 	{ "/who", inputWho },
+	{ "/whois", inputWhois },
 };
 static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);