Extend WHOIS info
Diff
src/connection.rs | 19 ++++++++++++++++++-
src/server/response.rs | 44 +++++++++++++++++++++++++++++++++++++++-----
2 files changed, 57 insertions(+), 6 deletions(-)
@@ -4,6 +4,7 @@ mod authenticate;
pub mod sasl;
use std::{
fmt::{Display, Formatter},
io::{Error, ErrorKind},
net::SocketAddr,
str::FromStr,
@@ -98,7 +99,7 @@ impl TryFrom<ConnectionRequest> for InitiatedConnection {
Ok(Self {
host,
cloak: host.ip().to_string(),
cloak: format!("0{}", host.ip()),
nick,
user,
mode: UserMode::empty(),
@@ -298,6 +299,22 @@ bitflags! {
}
}
impl Display for UserMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "+")?;
if self.contains(Self::WALLOPS) {
write!(f, "w")?;
}
if self.contains(Self::OPER) {
write!(f, "o")?;
}
Ok(())
}
}
impl Capability {
pub const SUPPORTED: &'static [&'static str] = &[
"userhost-in-names",
@@ -25,6 +25,16 @@ impl IntoProtocol for Whois {
),
}
};
($response:literal, $($payload:expr),*) => {
Message {
tags: None,
prefix: Some(Prefix::ServerName(SERVER_NAME.to_string())),
command: Command::Raw(
format!("{:03}", $response),
vec![for_user.to_string(), $($payload),*],
),
}
};
}
let Some(conn) = self.conn else {
@@ -42,11 +52,16 @@ impl IntoProtocol for Whois {
let mut out = vec![
msg!(
307,
conn.nick.to_string(),
"has identified for this nick".to_string()
), msg!(
RPL_WHOISUSER,
conn.nick.to_string(),
conn.user,
conn.user.to_string(),
conn.cloak,
"*".to_string(),
conn.real_name
),
@@ -64,11 +79,30 @@ impl IntoProtocol for Whois {
"seconds idle, signon time".to_string()
), msg!(RPL_WHOISCHANNELS, conn.nick.to_string(), channels),
msg!(
330,
conn.nick.to_string(),
conn.user.to_string(),
"is logged in as".to_string()
), msg!(
378,
conn.nick.to_string(),
format!(
"is connecting from {}@{} {}",
conn.user, conn.host, conn.host
)
), ];
if !conn.mode.is_empty() {
out.push(msg!(
379,
conn.nick.to_string(),
format!("is using modes {}", conn.mode)
)); }
if let Some(msg) = conn.away {
out.push(msg!(RPL_AWAY, conn.nick.to_string(), msg));
}