-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use super::*; | ||
use itertools::Itertools; | ||
|
||
/// "The USERHOST command takes up to five nicknames, each a separate parameters." | ||
/// -- https://modern.ircdocs.horse/#userhost-message | ||
const MAX_TARGETS: usize = 5; | ||
|
||
fn away_char(user: &wrapper::User) -> char { | ||
if user.away_reason().is_some() { | ||
'-' | ||
} else { | ||
'+' | ||
} | ||
} | ||
|
||
#[command_handler("USERHOST")] | ||
/// Syntax: USERHOST <nickname>{ <nickname>} | ||
fn userhost_handler( | ||
response: &dyn CommandResponse, | ||
network: &Network, | ||
args: ArgList, | ||
) -> CommandResult { | ||
if args.is_empty() { | ||
Err(CommandError::NotEnoughParameters) | ||
} else { | ||
let reply = args | ||
.iter() | ||
.take(MAX_TARGETS) | ||
.flat_map(Nickname::convert) | ||
.flat_map(|nick| network.user_by_nick(&nick)) | ||
.map(|user| { | ||
format!( | ||
"{}={}{}@{}", | ||
user.nick(), | ||
away_char(&user), | ||
user.user(), | ||
user.visible_host() | ||
) | ||
}) | ||
.join(" "); | ||
|
||
response.numeric(make_numeric!(Userhost, &reply)); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ mod handlers { | |
mod rename; | ||
mod topic; | ||
mod user; | ||
mod userhost; | ||
mod who; | ||
mod whois; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters