45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use futures::StreamExt;
|
|
use irc::client::prelude::Config as IrcConfig;
|
|
use irc::client::prelude::*;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
struct Config {
|
|
quit_message: String,
|
|
irc: IrcConfig,
|
|
}
|
|
|
|
macro_rules! unwrap_or_continue {
|
|
($o:expr) => {
|
|
match $o {
|
|
Some(v) => v,
|
|
None => continue,
|
|
}
|
|
};
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let filename = std::env::var("SLEEPERAGENT_CONFIG").unwrap_or("sleeperagent.toml".into());
|
|
let contents = tokio::fs::read_to_string(filename).await?;
|
|
|
|
let conf: Config = toml::from_str(&contents)?;
|
|
|
|
let mut client = Client::from_config(conf.irc).await?;
|
|
client.identify()?;
|
|
|
|
let mut stream = client.stream()?;
|
|
|
|
while let Some(message) = stream.next().await.transpose()? {
|
|
let nick = unwrap_or_continue!(message.source_nickname());
|
|
match message.command {
|
|
Command::PRIVMSG(ref channel, ref message) => {
|
|
client.send_privmsg(channel, format!("<{}> {}", nick, message))?;
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|