rust-irc/src/bin/build-bot.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

2018-10-07 18:06:29 +02:00
extern crate irc;
use irc::client::prelude::*;
use std::default::Default;
use std::env;
fn main() {
let repository_slug = env::var("TRAVIS_REPO_SLUG").unwrap();
let branch = env::var("TRAVIS_BRANCH").unwrap();
let commit = env::var("TRAVIS_COMMIT").unwrap();
let commit_message = env::var("TRAVIS_COMMIT_MESSAGE").unwrap();
let config = Config {
nickname: Some("irc-crate-ci".to_owned()),
server: Some("irc.pdgn.co".to_owned()),
use_ssl: Some(true),
..Default::default()
};
let mut reactor = IrcReactor::new().unwrap();
2019-06-11 03:52:36 +02:00
let client = reactor.prepare_client_and_connect(config).unwrap();
2018-10-07 18:06:29 +02:00
client.identify().unwrap();
reactor.register_client_with_handler(client, move |client, message| {
match message.command {
Command::Response(Response::RPL_ISUPPORT, _, _) => {
client.send_privmsg(
"#commits",
format!(
2018-10-13 00:11:02 +02:00
"[{}/{}] ({}) {}",
repository_slug,
branch,
&commit[..7],
commit_message
2018-10-07 18:06:29 +02:00
),
)?;
client.send_quit("QUIT")?;
}
_ => (),
};
Ok(())
});
reactor.run().unwrap();
}