update to use tokio spawn
This commit is contained in:
parent
16b32a554c
commit
677f5aede7
53
src/main.rs
53
src/main.rs
@ -37,13 +37,15 @@ async fn main() -> Result<(), failure::Error> {
|
||||
|
||||
let out = cmd.output().unwrap();
|
||||
|
||||
let output = String::from_utf8_lossy(&out.stdout);
|
||||
let output = String::from_utf8_lossy(&out.stdout).to_string();
|
||||
|
||||
let lines = output.lines();
|
||||
let s = sender.clone();
|
||||
|
||||
for l in lines {
|
||||
sender.send_privmsg(target, l)?;
|
||||
}
|
||||
let t = target.to_string();
|
||||
|
||||
tokio::spawn(async move {
|
||||
send_message(s, t, output).await
|
||||
});
|
||||
}
|
||||
|
||||
if &msg[1..2] == "p" {
|
||||
@ -57,30 +59,35 @@ async fn main() -> Result<(), failure::Error> {
|
||||
|
||||
let out = cmd.output().unwrap();
|
||||
|
||||
let outerr = String::from_utf8_lossy(&out.stderr);
|
||||
let output = String::from_utf8_lossy(&out.stdout);
|
||||
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
|
||||
let output = String::from_utf8_lossy(&out.stdout).to_string();
|
||||
|
||||
let lines = outerr.lines();
|
||||
let s = sender.clone();
|
||||
|
||||
for l in lines {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
sender.send_privmsg(target, l)?;
|
||||
let t = target.to_string();
|
||||
|
||||
tokio::spawn(async move {
|
||||
send_message(s, t, outerr).await
|
||||
});
|
||||
|
||||
let s = sender.clone();
|
||||
let t = target.to_string();
|
||||
|
||||
tokio::spawn(async move {
|
||||
send_message(s.clone(), t, output).await
|
||||
});
|
||||
}
|
||||
|
||||
let lines = output.lines();
|
||||
|
||||
for l in lines {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
sender.send_privmsg(target, l)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if msg.contains(client.current_nickname()) {
|
||||
sender.send_privmsg(target, "Hi!")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn send_message(sender: irc::client::Sender, target: String, msg: String) -> Result<(), failure::Error> {
|
||||
for l in msg.lines() {
|
||||
sender.send_privmsg(target.clone(), l)?;
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user