uberbot/src/bots/weeb.rs

15 lines
455 B
Rust
Raw Normal View History

use serde_json::Value;
pub async fn get_waifu_pic(category: &str) -> anyhow::Result<Option<String>> {
let api_resp = reqwest::get(format!("https://api.waifu.pics/sfw/{}", category))
.await?
.text()
.await?;
let api_resp = api_resp.trim();
2021-12-30 17:02:12 -06:00
tracing::debug!("API response: {}", api_resp);
let value: Value = serde_json::from_str(&api_resp)?;
let url = value["url"].as_str().map(|v| v.to_string());
Ok(url)
2021-12-27 15:24:15 -06:00
}