blob: 2ec24c0a8aae3e9ae35785deebdc038815f46b72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}
}
}
}
}
|