feat: set presence info on ready again
Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
1c168bd8ba
commit
5b16c14b45
5 changed files with 55 additions and 5 deletions
41
src/api/prism_meta.rs
Normal file
41
src/api/prism_meta.rs
Normal 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}",
|
||||
))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue