Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/libtiny_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 43 additions & 1 deletion crates/tiny/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn find_client<'a>(clients: &'a mut Vec<Client>, serv_name: &str) -> Option<&'a

////////////////////////////////////////////////////////////////////////////////////////////////////

static CMDS: [&Cmd; 9] = [
static CMDS: [&Cmd; 10] = [
&AWAY_CMD,
&CLOSE_CMD,
&CONNECT_CMD,
Expand All @@ -106,6 +106,7 @@ static CMDS: [&Cmd; 9] = [
&MSG_CMD,
&NAMES_CMD,
&NICK_CMD,
&WHOIS_CMD,
&HELP_CMD,
];

Expand Down Expand Up @@ -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 <nick>`",
};

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,
Expand Down