Add cleverbot

This commit is contained in:
Sakuhl 2018-03-07 11:38:31 +01:00
parent 4a777bda38
commit d46165e378

View File

@ -146,17 +146,42 @@ impl EventHandler for Handler {
}
}
lazy_static! {
static ref CS: Mutex<Option<String>> = Mutex::new(None);
}
#[derive(Deserialize)]
struct CBResponse {
cs: String,
output: String
}
impl Handler {
fn process_message(&self, msg: &Message, prefix: &str) -> Result<(), Error> {
if msg.content == "<@392763365409292298> has big gay" {
let _ = msg.channel_id.broadcast_typing();
thread::sleep_ms(5000);
let _ = msg.channel_id.say("<@395463760841539584> has bigger gay");
return Ok(());
}
if msg.content == "<@392763365409292298> has biggest gay" {
let _ = msg.channel_id.broadcast_typing();
thread::sleep_ms(5000);
let _ = msg.channel_id.say("<@395463760841539584> no u");
return Ok(());
}
if msg.content.contains("<@392763365409292298>") {
let _ = msg.channel_id.broadcast_typing();
println!("{:?}", *CS);
let resp = reqwest::get(&format!("http://www.cleverbot.com/getreply?key=CC7wgO9gQl7yPjB54eDLHmM5Jmg&input={}&cb_settings_tweak1=100{}",
msg.content.replace("<@392763365409292298>", ""), (*CS).lock().clone().map(|x| format!("&cs={}", x)).unwrap_or_else(String::new)))?
.error_for_status()?
.text()?;
thread::sleep_ms(500);
let resp: CBResponse = serde_json::from_str(&resp)?;
*(*CS).lock() = Some(resp.cs);
msg.channel_id.say(format!("{} {}", msg.author.mention(), resp.output))?;
return Ok(());
}
if !msg.content.starts_with(&prefix) {
return Ok(());