Add /whois

master
Curtis McEnroe 2018-11-29 05:37:10 -05:00
parent 3b3b0d65c3
commit e4eb97e512
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 71 additions and 2 deletions

View File

@ -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

View File

@ -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 },

12
input.c
View File

@ -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]);