summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
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 },
ui.c?h=2.2a&id=872608e5c4fb814604a359a4b8b2f3bcf317cf0f&follow=1'>Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe