rust-irc/examples/simple.rs

31 lines
806 B
Rust
Raw Permalink Normal View History

2019-08-27 15:05:51 +02:00
use futures::prelude::*;
2015-02-23 03:22:33 +01:00
use irc::client::prelude::*;
2019-08-27 15:05:51 +02:00
#[tokio::main]
async fn main() -> irc::error::Result<()> {
let config = Config {
2017-06-19 19:46:01 +02:00
nickname: Some("pickles".to_owned()),
server: Some("chat.freenode.net".to_owned()),
channels: vec!["#rust-spam".to_owned()],
2017-06-19 19:59:26 +02:00
..Default::default()
};
2019-08-27 15:05:51 +02:00
let mut client = Client::from_config(config).await?;
client.identify()?;
let mut stream = client.stream()?;
let sender = client.sender();
2019-08-27 15:05:51 +02:00
while let Some(message) = stream.next().await.transpose()? {
print!("{}", message);
2021-11-14 21:03:16 +01:00
if let Command::PRIVMSG(ref target, ref msg) = message.command {
if msg.contains(client.current_nickname()) {
sender.send_privmsg(target, "Hi!")?;
2017-06-19 19:59:26 +02:00
}
}
2019-08-27 15:05:51 +02:00
}
Ok(())
}