Add /whois
This commit is contained in:
		
							parent
							
								
									3b3b0d65c3
								
							
						
					
					
						commit
						e4eb97e512
					
				@ -185,6 +185,9 @@ Switch to view for
 | 
				
			|||||||
.
 | 
					.
 | 
				
			||||||
.It Ic /who
 | 
					.It Ic /who
 | 
				
			||||||
List users in the current channel.
 | 
					List users in the current channel.
 | 
				
			||||||
 | 
					.
 | 
				
			||||||
 | 
					.It Ic /whois Ar nick
 | 
				
			||||||
 | 
					Query information about a user.
 | 
				
			||||||
.El
 | 
					.El
 | 
				
			||||||
.
 | 
					.
 | 
				
			||||||
.Pp
 | 
					.Pp
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										58
									
								
								handle.c
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								handle.c
									
									
									
									
									
								
							@ -21,6 +21,7 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <sysexits.h>
 | 
					#include <sysexits.h>
 | 
				
			||||||
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "chat.h"
 | 
					#include "chat.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -129,6 +130,58 @@ static void handleReplyMOTD(char *prefix, char *params) {
 | 
				
			|||||||
	uiFmt(TagStatus, UICold, "%s", mesg);
 | 
						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) {
 | 
					static void handleJoin(char *prefix, char *params) {
 | 
				
			||||||
	char *nick, *user, *chan;
 | 
						char *nick, *user, *chan;
 | 
				
			||||||
	shift(prefix, &nick, &user, NULL, params, 1, 0, &chan);
 | 
						shift(prefix, &nick, &user, NULL, params, 1, 0, &chan);
 | 
				
			||||||
@ -400,7 +453,12 @@ static const struct {
 | 
				
			|||||||
	Handler handler;
 | 
						Handler handler;
 | 
				
			||||||
} Handlers[] = {
 | 
					} Handlers[] = {
 | 
				
			||||||
	{ "001", handleReplyWelcome },
 | 
						{ "001", handleReplyWelcome },
 | 
				
			||||||
 | 
						{ "311", handleReplyWhoisUser },
 | 
				
			||||||
 | 
						{ "312", handleReplyWhoisServer },
 | 
				
			||||||
 | 
						{ "313", handleReplyWhoisOperator },
 | 
				
			||||||
	{ "315", handleReplyEndOfWho },
 | 
						{ "315", handleReplyEndOfWho },
 | 
				
			||||||
 | 
						{ "317", handleReplyWhoisIdle },
 | 
				
			||||||
 | 
						{ "319", handleReplyWhoisChannels },
 | 
				
			||||||
	{ "332", handleReplyTopic },
 | 
						{ "332", handleReplyTopic },
 | 
				
			||||||
	{ "352", handleReplyWho },
 | 
						{ "352", handleReplyWho },
 | 
				
			||||||
	{ "366", handleReplyEndOfNames },
 | 
						{ "366", handleReplyEndOfNames },
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								input.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								input.c
									
									
									
									
									
								
							@ -87,6 +87,13 @@ static void inputWho(struct Tag tag, char *params) {
 | 
				
			|||||||
	ircFmt("WHO %s\r\n", tag.name);
 | 
						ircFmt("WHO %s\r\n", tag.name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void inputWhois(struct Tag tag, char *params) {
 | 
				
			||||||
 | 
						(void)tag;
 | 
				
			||||||
 | 
						char *nick = param("/whois", ¶ms, "nick");
 | 
				
			||||||
 | 
						if (!nick) return;
 | 
				
			||||||
 | 
						ircFmt("WHOIS %s\r\n", nick);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void inputTopic(struct Tag tag, char *params) {
 | 
					static void inputTopic(struct Tag tag, char *params) {
 | 
				
			||||||
	if (params) {
 | 
						if (params) {
 | 
				
			||||||
		ircFmt("TOPIC %s :%s\r\n", tag.name, 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;
 | 
						(void)params;
 | 
				
			||||||
	urlList(tag);
 | 
						urlList(tag);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -163,9 +170,10 @@ static const struct {
 | 
				
			|||||||
	{ "/query", inputQuery },
 | 
						{ "/query", inputQuery },
 | 
				
			||||||
	{ "/quit", inputQuit },
 | 
						{ "/quit", inputQuit },
 | 
				
			||||||
	{ "/topic", inputTopic },
 | 
						{ "/topic", inputTopic },
 | 
				
			||||||
	{ "/url", inputUrl },
 | 
						{ "/url", inputURL },
 | 
				
			||||||
	{ "/view", inputView },
 | 
						{ "/view", inputView },
 | 
				
			||||||
	{ "/who", inputWho },
 | 
						{ "/who", inputWho },
 | 
				
			||||||
 | 
						{ "/whois", inputWhois },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);
 | 
					static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user