Skip to content

Commit cbdc9cc

Browse files
Add support for /whois command
Add support for the /whois command using the raw_msg function on the connection for the particular server.
1 parent c353066 commit cbdc9cc

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

crates/libtiny_client/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ impl Client {
161161
self.state.is_nick_accepted()
162162
}
163163

164+
/// Query the server for a nick to get more information about the user
165+
pub fn whois(&mut self, nick: &str) {
166+
self.raw_msg(&format!("WHOIS {}", nick));
167+
}
168+
164169
/// Send a message directly to the server. "\r\n" suffix is added by this method.
165170
pub fn raw_msg(&mut self, msg: &str) {
166171
self.msg_chan

crates/tiny/src/cmd.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn find_client<'a>(clients: &'a mut Vec<Client>, serv_name: &str) -> Option<&'a
9797

9898
////////////////////////////////////////////////////////////////////////////////////////////////////
9999

100-
static CMDS: [&Cmd; 9] = [
100+
static CMDS: [&Cmd; 10] = [
101101
&AWAY_CMD,
102102
&CLOSE_CMD,
103103
&CONNECT_CMD,
@@ -106,6 +106,7 @@ static CMDS: [&Cmd; 9] = [
106106
&MSG_CMD,
107107
&NAMES_CMD,
108108
&NICK_CMD,
109+
&WHOIS_CMD,
109110
&HELP_CMD,
110111
];
111112

@@ -511,6 +512,47 @@ fn nick(args: CmdArgs) {
511512
}
512513
}
513514

515+
////////////////////////////////////////////////////////////////////////////////////////////////////
516+
517+
static WHOIS_CMD: Cmd = Cmd {
518+
name: "whois",
519+
cmd_fn: whois,
520+
description: "whois lookup for a user",
521+
usage: "`/whois <nick>`",
522+
};
523+
524+
fn whois(args: CmdArgs) {
525+
let CmdArgs {
526+
args,
527+
ui,
528+
clients,
529+
src,
530+
..
531+
} = args;
532+
533+
let words: Vec<&str> = args.split_whitespace().collect();
534+
535+
// Allow lookup for only one user at a time
536+
if let Some(client) = find_client(clients, src.serv_name()) {
537+
match words.get(0) {
538+
Some(word) => client.whois(&word),
539+
None => {
540+
ui.add_client_err_msg(
541+
&format!("Usage: {}", WHOIS_CMD.usage),
542+
&MsgTarget::CurrentTab,
543+
);
544+
}
545+
};
546+
} else {
547+
ui.add_client_err_msg(
548+
&format!("Usage: {}", WHOIS_CMD.usage),
549+
&MsgTarget::CurrentTab,
550+
);
551+
}
552+
}
553+
554+
////////////////////////////////////////////////////////////////////////////////////////////////////
555+
514556
static HELP_CMD: Cmd = Cmd {
515557
name: "help",
516558
cmd_fn: help,

0 commit comments

Comments
 (0)