initial rewrite in rust & moderation commands

Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
seth 2023-12-03 04:11:57 -05:00
parent b17e357b75
commit 45403e9d9b
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
53 changed files with 3297 additions and 2820 deletions

42
src/api/rory.rs Normal file
View file

@ -0,0 +1,42 @@
use crate::api::REQWEST_CLIENT;
use color_eyre::eyre::{eyre, Result};
use log::*;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct RoryResponse {
pub id: u64,
pub url: String,
}
const RORY: &str = "https://rory.cat";
const ENDPOINT: &str = "/purr";
pub async fn get_rory(id: Option<u64>) -> Result<RoryResponse> {
let target = {
if let Some(id) = id {
id.to_string()
} else {
"".to_string()
}
};
let req = REQWEST_CLIENT
.get(format!("{RORY}{ENDPOINT}/{target}"))
.build()?;
info!("making request to {}", req.url());
let resp = REQWEST_CLIENT.execute(req).await?;
let status = resp.status();
if let StatusCode::OK = status {
let data = resp.json::<RoryResponse>().await?;
Ok(data)
} else {
Err(eyre!(
"Failed to get rory from {RORY}{ENDPOINT}/{target} with {status}",
))
}
}