summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs43
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);
+ }
+ }
+ }
+ }
+}