feat: set presence info on ready again

Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
seth 2023-12-04 09:09:49 -05:00
parent 1c168bd8ba
commit 5b16c14b45
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
5 changed files with 55 additions and 5 deletions

41
src/api/prism_meta.rs Normal file
View file

@ -0,0 +1,41 @@
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 MinecraftPackageJson {
pub format_version: u8,
pub name: String,
pub recommended: Vec<String>,
pub uid: String,
}
const PRISM_META: &str = "https://meta.prismlauncher.org/v1";
const MINECRAFT_PACKAGEJSON_ENDPOINT: &str = "/net.minecraft/package.json";
pub async fn get_latest_minecraft_version() -> Result<String> {
let req = REQWEST_CLIENT
.get(format!("{PRISM_META}{MINECRAFT_PACKAGEJSON_ENDPOINT}"))
.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::<MinecraftPackageJson>().await?;
let version = data
.recommended
.first()
.ok_or_else(|| eyre!("Couldn't find first recommended version!"))?;
Ok(version.clone())
} else {
Err(eyre!(
"Failed to get latest Minecraft version from {PRISM_META}{MINECRAFT_PACKAGEJSON_ENDPOINT} with {status}",
))
}
}