Parse PRIVMSGs
This commit is contained in:
parent
ab4c1dd010
commit
901e0e0baf
10
src/lib.rs
10
src/lib.rs
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue