Expose the usser who sent the PRIVMSG
This commit is contained in:
parent
f57e65d588
commit
bb3d7059b9
|
@ -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())
|
||||
|
|
|
@ -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<str>
|
||||
}
|
||||
PRIVMSG(target, message) => {
|
||||
PRIVMSG(_, target, message) => {
|
||||
let formatted = format!("PRIVMSG {} {}", target, message);
|
||||
Cow::Owned(formatted) as Cow<str>
|
||||
}
|
||||
|
@ -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(),
|
||||
))?;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue