Parse PRIVMSGs

This commit is contained in:
Yash Karandikar 2021-11-04 13:37:32 -05:00
parent ab4c1dd010
commit 901e0e0baf
Signed by: karx
GPG key ID: A794DA2529474BA5
2 changed files with 13 additions and 1 deletions

View file

@ -116,6 +116,16 @@ impl Command {
if new.starts_with("PING") {
let command: String = String::from(new.split_whitespace().collect::<Vec<&str>>()[1]);
return Self::PING(command);
} else if new.contains("PRIVMSG") {
let parts: Vec<&str> = new.split_whitespace().collect();
let target = parts[2];
let mut builder = String::new();
for part in parts[3..].to_vec() {
builder.push_str(&format!("{} ", part));
}
return Self::PRIVMSG(target.to_string(), (&builder[1..]).to_string());
}
Self::OTHER(new.to_string())

View file

@ -21,13 +21,15 @@ fn main() -> Result<(), std::io::Error> {
);*/
let mut client = Client::new(config)?;
client.identify()?;
client.write_command(Command::PRIVMSG("#main".to_string(), "Hello".to_string()))?;
loop {
if let Ok(ref command) = client.read() {
if let Command::OTHER(line) = command {
print!("{}", line);
}
if let Command::PRIVMSG(channel, message) = command {
println!("PRIVMSG received: {} {}", channel, message);
}
}
}
}