diff --git a/crates/libtiny_client/src/lib.rs b/crates/libtiny_client/src/lib.rs index 6809ec67..da0b29d6 100644 --- a/crates/libtiny_client/src/lib.rs +++ b/crates/libtiny_client/src/lib.rs @@ -161,6 +161,11 @@ impl Client { self.state.is_nick_accepted() } + /// Query the server for a nick to get more information about the user + pub fn whois(&mut self, nick: &str) { + self.raw_msg(&format!("WHOIS {}", nick)); + } + /// Send a message directly to the server. "\r\n" suffix is added by this method. pub fn raw_msg(&mut self, msg: &str) { self.msg_chan diff --git a/crates/tiny/src/cmd.rs b/crates/tiny/src/cmd.rs index a385a16c..6b13437a 100644 --- a/crates/tiny/src/cmd.rs +++ b/crates/tiny/src/cmd.rs @@ -97,7 +97,7 @@ fn find_client<'a>(clients: &'a mut Vec, serv_name: &str) -> Option<&'a //////////////////////////////////////////////////////////////////////////////////////////////////// -static CMDS: [&Cmd; 9] = [ +static CMDS: [&Cmd; 10] = [ &AWAY_CMD, &CLOSE_CMD, &CONNECT_CMD, @@ -106,6 +106,7 @@ static CMDS: [&Cmd; 9] = [ &MSG_CMD, &NAMES_CMD, &NICK_CMD, + &WHOIS_CMD, &HELP_CMD, ]; @@ -511,6 +512,47 @@ fn nick(args: CmdArgs) { } } +//////////////////////////////////////////////////////////////////////////////////////////////////// + +static WHOIS_CMD: Cmd = Cmd { + name: "whois", + cmd_fn: whois, + description: "whois lookup for a user", + usage: "`/whois `", +}; + +fn whois(args: CmdArgs) { + let CmdArgs { + args, + ui, + clients, + src, + .. + } = args; + + let words: Vec<&str> = args.split_whitespace().collect(); + + // Allow lookup for only one user at a time + if let Some(client) = find_client(clients, src.serv_name()) { + match words.get(0) { + Some(word) => client.whois(&word), + None => { + ui.add_client_err_msg( + &format!("Usage: {}", WHOIS_CMD.usage), + &MsgTarget::CurrentTab, + ); + } + }; + } else { + ui.add_client_err_msg( + &format!("Usage: {}", WHOIS_CMD.usage), + &MsgTarget::CurrentTab, + ); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + static HELP_CMD: Cmd = Cmd { name: "help", cmd_fn: help,