diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-27 08:14:40 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-27 08:14:40 -0500 |
commit | ed9dff167471dc1e84963e4c56dbfda0a7edbc73 (patch) | |
tree | 0093cbd18defc18c64b49b9bb317dfb38ad0f1b7 /src |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2ec24c0 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,43 @@ +extern crate hyper; +extern crate irc; + +use std::io::Read; + +use hyper::Client; +use hyper::header::Connection; + +use irc::client::prelude::*; + +fn main() { + let config = Config { + nickname: Some(format!("lidavidm_prime")), + server: Some(format!("irc.freenode.net")), + channels: Some(vec![format!("#opensourcecornell")]), + .. Default::default() + }; + let server = IrcServer::from_config(config).unwrap(); + server.identify().unwrap(); + for message in server.iter() { + let message = message.unwrap(); // We'll just panic if there's an error. + print!("{}", message.into_string()); + if &message.command[..] == "PRIVMSG" { + if let Some(msg) = message.suffix { + if msg.starts_with("!wiki") { + let article = msg[5..].trim(); + let response = format!("Looking up \"{}\" on Wikipedia for you...", article); + server.send_privmsg(&message.args[0], &response).unwrap(); + + let mut client = Client::new(); + let mut res = client.get("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=&explaintext=&titles={}&redirects=") + .header(Connection::close()) + .send().unwrap(); + + let mut body = String::new(); + res.read_to_string(&mut body).unwrap(); + + println!("Response: {}", body); + } + } + } + } +} |