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); } } } } }