diff --git a/src/commands.rs b/src/commands.rs index 4532969..12d510d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -142,6 +142,8 @@ pub enum Command { /// # Ok::<(), std::io::Error>(()) /// ``` PRIVMSG( + /// Source Nickname + String, /// Channel String, /// Message @@ -185,6 +187,9 @@ impl Command { let command = parts[1].to_string(); return Self::PONG(command); } else if parts[1] == "PRIVMSG" { + let nick = parts[0]; + let index = nick.chars().position(|c| c == '!').unwrap(); + let nick = String::from(&nick[1..index]); let target = parts[2]; let mut builder = String::new(); @@ -192,7 +197,7 @@ impl Command { builder.push_str(&format!("{} ", part)); } - return Self::PRIVMSG(target.to_string(), (&builder[1..]).to_string()); + return Self::PRIVMSG(nick, target.to_string(), (&builder[1..]).to_string()); } Self::OTHER(new.to_string()) diff --git a/src/lib.rs b/src/lib.rs index d6bb1dd..a2dfdf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,8 @@ //! if let Command::OTHER(line) = command { //! print!("{}", line); //! } -//! if let Command::PRIVMSG(channel, message) = command { -//! println!("PRIVMSG received: {} {}", channel, message); +//! if let Command::PRIVMSG(nick, channel, message) = command { +//! println!("PRIVMSG received from {}: {} {}", nick, channel, message); //! } //! } //! # break; @@ -209,7 +209,7 @@ impl Client { /// ```no_run /// # use circe::*; /// # let mut client = Client::new(Config::from_toml("config.toml")?)?; - /// client.write_command(Command::PRIVMSG("#main".to_string(), "Hello".to_string()))?; + /// client.write_command(Command::PRIVMSG("".to_string() "#main".to_string(), "Hello".to_string()))?; /// # Ok::<(), std::io::Error>(()) /// ``` /// Returns error if the client could not write to the stream. @@ -299,7 +299,7 @@ impl Client { let formatted = format!("PONG {}", code); Cow::Owned(formatted) as Cow } - PRIVMSG(target, message) => { + PRIVMSG(_, target, message) => { let formatted = format!("PRIVMSG {} {}", target, message); Cow::Owned(formatted) as Cow } @@ -362,6 +362,7 @@ impl Client { /// ``` pub fn privmsg(&mut self, channel: &str, message: &str) -> Result<(), Error> { self.write_command(commands::Command::PRIVMSG( + String::from(""), channel.to_string(), message.to_string(), ))?; diff --git a/src/main.rs b/src/main.rs index d0d84dd..e267bb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), std::io::Error> { if let Command::OTHER(line) = command { print!("{}", line); } - if let Command::PRIVMSG(channel, message) = command { + if let Command::PRIVMSG(nick, channel, message) = command { if message.contains("!quit") { client.quit(None)?; break; @@ -37,7 +37,7 @@ fn main() -> Result<(), std::io::Error> { if message.contains("!close") { client.part("#main")?; } - println!("PRIVMSG received: {} {}", channel, message); + println!("PRIVMSG received from {}: {} {}", nick, channel, message); } } }