summaryrefslogtreecommitdiff
path: root/src/commands/random_shiggy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/random_shiggy.rs')
-rw-r--r--src/commands/random_shiggy.rs31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/commands/random_shiggy.rs b/src/commands/random_shiggy.rs
index b1f1511..c6aa6de 100644
--- a/src/commands/random_shiggy.rs
+++ b/src/commands/random_shiggy.rs
@@ -1,36 +1,9 @@
-use crate::api::guzzle::REQWEST_CLIENT;
-use reqwest::StatusCode;
-use serde::Deserialize;
+use crate::api::shiggy::get_random_shiggy;
use serenity::builder::CreateApplicationCommand;
use serenity::model::prelude::application_command::CommandDataOption;
-const URL: &str = "https://safebooru.donmai.us/posts/random.json?tags=kemomimi-chan_(naga_u)+naga_u&only=file_url";
-const ERROR_MSG: &str = "couldn't get a shiggy";
-
-#[derive(Deserialize)]
-struct SafebooruResponse {
- file_url: String,
-}
-
pub async fn run(_: &[CommandDataOption]) -> String {
- let resp = match REQWEST_CLIENT
- .execute(REQWEST_CLIENT.get(URL).build().unwrap())
- .await
- {
- Ok(r) => r,
- Err(e) => return format!("{} ({:?})", ERROR_MSG, e),
- };
-
- match resp.status() {
- StatusCode::OK => match resp.json::<SafebooruResponse>().await {
- Ok(sr) => sr.file_url,
- Err(e) => format!("{} ({:?})", ERROR_MSG, e),
- },
- other => {
- println!("{}", resp.text().await.unwrap());
- format!("{} ({:?})", ERROR_MSG, other)
- }
- }
+ get_random_shiggy().await
}
pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {