diff --git a/src/api/dadjoke.rs b/src/api/dadjoke.rs index d3ac9c6f..b29e2bfe 100644 --- a/src/api/dadjoke.rs +++ b/src/api/dadjoke.rs @@ -16,6 +16,6 @@ pub async fn get_joke() -> Result { if let StatusCode::OK = status { Ok(resp.text().await?) } else { - Err(eyre!("Failed to fetch joke from {DADJOKE} with {status}")) + Err(eyre!("Couldn't get a joke!")) } } diff --git a/src/api/prism_meta.rs b/src/api/prism_meta.rs index 0bfa3fa0..ce6adf18 100644 --- a/src/api/prism_meta.rs +++ b/src/api/prism_meta.rs @@ -1,6 +1,6 @@ use crate::api::REQWEST_CLIENT; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::{eyre, Context, Result}; use log::*; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -27,11 +27,15 @@ pub async fn get_latest_minecraft_version() -> Result { let status = resp.status(); if let StatusCode::OK = status { - let data = resp.json::().await?; + let data = resp + .json::() + .await + .wrap_err_with(|| "Couldn't parse Minecraft versions!")?; + let version = data .recommended .first() - .ok_or_else(|| eyre!("Couldn't find first recommended version!"))?; + .ok_or_else(|| eyre!("Couldn't find latest version of Minecraft!"))?; Ok(version.clone()) } else { diff --git a/src/api/rory.rs b/src/api/rory.rs index 9e56e8d5..63be4500 100644 --- a/src/api/rory.rs +++ b/src/api/rory.rs @@ -1,6 +1,6 @@ use crate::api::REQWEST_CLIENT; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::{eyre, Context, Result}; use log::*; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; pub struct RoryResponse { pub id: u64, pub url: String, + pub error: Option, } const RORY: &str = "https://rory.cat"; @@ -25,14 +26,22 @@ pub async fn get_rory(id: Option) -> Result { let req = REQWEST_CLIENT .get(format!("{RORY}{ENDPOINT}/{target}")) - .build()?; + .build() + .wrap_err_with(|| "Couldn't build reqwest client!")?; info!("Making request to {}", req.url()); - let resp = REQWEST_CLIENT.execute(req).await?; + let resp = REQWEST_CLIENT + .execute(req) + .await + .wrap_err_with(|| "Couldn't make request for shiggy!")?; let status = resp.status(); if let StatusCode::OK = status { - let data = resp.json::().await?; + let data = resp + .json::() + .await + .wrap_err_with(|| "Couldn't parse the shiggy response!")?; + Ok(data) } else { Err(eyre!( diff --git a/src/commands/general/rory.rs b/src/commands/general/rory.rs index ea62d1da..59d157ec 100644 --- a/src/commands/general/rory.rs +++ b/src/commands/general/rory.rs @@ -9,14 +9,18 @@ pub async fn rory( ctx: Context<'_>, #[description = "specify a Rory ID"] id: Option, ) -> Result<()> { - let resp = get_rory(id).await?; + let rory = get_rory(id).await?; ctx.send(|m| { m.embed(|e| { - e.title("Rory :3") - .url(&resp.url) - .image(resp.url) - .footer(|f| f.text(format!("ID {}", resp.id))) + if let Some(error) = rory.error { + e.title("Error!").description(error) + } else { + e.title("Rory :3") + .url(&rory.url) + .image(rory.url) + .footer(|f| f.text(format!("ID {}", rory.id))) + } }) }) .await?; diff --git a/src/commands/general/say.rs b/src/commands/general/say.rs index 27cd82ff..6439f4b9 100644 --- a/src/commands/general/say.rs +++ b/src/commands/general/say.rs @@ -17,6 +17,7 @@ pub async fn say(ctx: Context<'_>, #[description = "Just content?"] content: Str .await .ok_or_else(|| eyre!("Couldn't get channel!"))?; + ctx.defer_ephemeral().await?; channel.say(ctx, &content).await?; ctx.say("I said what you said!").await?;