This commit is contained in:
parent
cb46761966
commit
2bc19d0301
69
src/main.rs
69
src/main.rs
@ -4,6 +4,8 @@ use futures::prelude::*;
|
||||
use irc::client::prelude::*;
|
||||
use std::{collections::HashMap, process};
|
||||
|
||||
static ART: &str = include_str!("ouch.txt");
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), failure::Error> {
|
||||
// We can also load the Config at runtime via Config::load("path/to/config.toml")
|
||||
@ -15,8 +17,6 @@ async fn main() -> Result<(), failure::Error> {
|
||||
..Config::default()
|
||||
};
|
||||
|
||||
let spamart = include_str!("ouch.txt");
|
||||
|
||||
let mut client = Client::from_config(config).await?;
|
||||
client.identify()?;
|
||||
|
||||
@ -50,7 +50,10 @@ async fn main() -> Result<(), failure::Error> {
|
||||
println!("{:?}", cmd);
|
||||
|
||||
let out = cmd.output().unwrap();
|
||||
sender.send_privmsg(&target, format!("Exit Code: {}", out.status.code().unwrap_or(-1)))?;
|
||||
sender.send_privmsg(
|
||||
&target,
|
||||
format!("Exit Code: {}", out.status.code().unwrap_or(-1)),
|
||||
)?;
|
||||
|
||||
let output = String::from_utf8_lossy(&out.stdout).to_string();
|
||||
|
||||
@ -69,7 +72,10 @@ async fn main() -> Result<(), failure::Error> {
|
||||
println!("{:?}", cmd);
|
||||
|
||||
let out = cmd.output().unwrap();
|
||||
sender.send_privmsg(&target, format!("Exit Code: {}", out.status.code().unwrap_or(-1)))?;
|
||||
sender.send_privmsg(
|
||||
&target,
|
||||
format!("Exit Code: {}", out.status.code().unwrap_or(-1)),
|
||||
)?;
|
||||
|
||||
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
|
||||
let output = String::from_utf8_lossy(&out.stdout).to_string();
|
||||
@ -84,12 +90,17 @@ async fn main() -> Result<(), failure::Error> {
|
||||
let t = target.to_string();
|
||||
|
||||
tokio::spawn(async move { send_message(s.clone(), t, output).await });
|
||||
},
|
||||
Some("!spam") => {
|
||||
let s = sender.clone();
|
||||
let t = target.clone();
|
||||
tokio::spawn(async move { send_message(s.clone(), t, spamart.to_string()).await });
|
||||
},
|
||||
}
|
||||
Some("!advert") => {
|
||||
let mut args = msg.split_ascii_whitespace().skip(1);
|
||||
let l = msg.split_ascii_whitespace().skip(1).count();
|
||||
if l == 2 {
|
||||
let net = args.next().unwrap().to_string();
|
||||
let chan = args.next().unwrap().to_string();
|
||||
println!("{} {}", net, chan);
|
||||
tokio::spawn(async move { target_advert(net, chan).await });
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -112,3 +123,41 @@ async fn send_message(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn target_advert(network: String, channel: String) -> Result<(), failure::Error> {
|
||||
let config = Config {
|
||||
nickname: Some("ouchie".to_owned()),
|
||||
server: Some(network),
|
||||
channels: vec![channel.clone()],
|
||||
..Config::default()
|
||||
};
|
||||
|
||||
let mut client = Client::from_config(config).await?;
|
||||
client.identify()?;
|
||||
|
||||
let mut stream = client.stream()?;
|
||||
let sender = client.sender();
|
||||
|
||||
while let Some(message) = stream.next().await.transpose()? {
|
||||
print!("{}", message);
|
||||
|
||||
if let Command::JOIN(_, _, _) = message.command {
|
||||
let sender = sender.clone();
|
||||
let channel = channel.clone();
|
||||
|
||||
println!("motd");
|
||||
|
||||
tokio::spawn(async move {
|
||||
println!("pre time");
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||
println!("post time");
|
||||
send_message(sender.clone(), channel, ART.to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
sender.send_quit("ouch or die").unwrap()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user