From eb41fede91d072693b279f908976d2ebc2ba1ca3 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 16 Jan 2022 00:02:56 -0500 Subject: format --- src/commands/osu.rs | 100 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 27 deletions(-) (limited to 'src/commands/osu.rs') diff --git a/src/commands/osu.rs b/src/commands/osu.rs index 28d3cb3..8d91f56 100644 --- a/src/commands/osu.rs +++ b/src/commands/osu.rs @@ -29,17 +29,24 @@ async fn setup_reqwest() -> Result { scope: "public".into(), }; - let req = reqwest::Client::new().post("https://osu.ppy.sh/oauth/token") - .json(&token_req).send().await? - .json::().await?; - + let req = reqwest::Client::new() + .post("https://osu.ppy.sh/oauth/token") + .json(&token_req) + .send() + .await? + .json::() + .await?; let mut headers = header::HeaderMap::new(); - headers.insert("Authorization", header::HeaderValue::from_str(format!("Bearer {}", req.access_token).as_str()).unwrap()); - + headers.insert( + "Authorization", + header::HeaderValue::from_str(format!("Bearer {}", req.access_token).as_str()).unwrap(), + ); + Ok(ClientBuilder::new() .default_headers(headers) - .build().unwrap()) + .build() + .unwrap()) } #[derive(Deserialize, Serialize, Clone, Debug)] @@ -75,14 +82,21 @@ struct OsuUserStatsGrades { /// Examples: /// ~osup muirrum #[poise::command(slash_command, prefix_command)] -pub async fn osup(ctx: Context<'_>, - #[description = "The osu! username or ID to look up"] - lookup: String, - ) -> Result<(), Error> { +pub async fn osup( + ctx: Context<'_>, + #[description = "The osu! username or ID to look up"] lookup: String, +) -> Result<(), Error> { let client = setup_reqwest().await?; - let mut res = client.get(format!("https://osu.ppy.sh/api/v2/users/{}?key=username", lookup)) - .send().await?.json::().await?; + let mut res = client + .get(format!( + "https://osu.ppy.sh/api/v2/users/{}?key=username", + lookup + )) + .send() + .await? + .json::() + .await?; res.country_code = res.country_code.to_lowercase(); @@ -90,13 +104,31 @@ pub async fn osup(ctx: Context<'_>, m.embed(|e| { e.title(format!("osu! Profile: {}", res.clone().username)); e.thumbnail(res.clone().avatar_url); - e.field("Ranks", format!(":map: #{}\n:flag_{}: #{}", res.clone().statistics.global_rank.unwrap_or(0), res.clone().country_code, res.clone().statistics.country_rank.unwrap_or(0u32)), true); - - e.field("Stats", format!("**PP:** {}\n**Acc:** {}%", res.clone().statistics.pp, res.clone().statistics.hit_accuracy.unwrap_or(0.0)), false); + e.field( + "Ranks", + format!( + ":map: #{}\n:flag_{}: #{}", + res.clone().statistics.global_rank.unwrap_or(0), + res.clone().country_code, + res.clone().statistics.country_rank.unwrap_or(0u32) + ), + true, + ); + + e.field( + "Stats", + format!( + "**PP:** {}\n**Acc:** {}%", + res.clone().statistics.pp, + res.clone().statistics.hit_accuracy.unwrap_or(0.0) + ), + false, + ); e }); m - }).await?; + }) + .await?; Ok(()) } @@ -140,28 +172,42 @@ struct OsuBeatMapSetCovers { /// Usage: /// ~osubm #[poise::command(slash_command, prefix_command)] -pub async fn osubm(ctx: Context<'_>, - #[description = "The beatmap ID"] - bm_id: u32, - ) -> Result<(), Error> { +pub async fn osubm( + ctx: Context<'_>, + #[description = "The beatmap ID"] bm_id: u32, +) -> Result<(), Error> { let client = setup_reqwest().await?; - let mut res = client.get(format!("https://osu.ppy.sh/api/v2/beatmaps/{}", bm_id)) - .send().await?.json::().await?; + let mut res = client + .get(format!("https://osu.ppy.sh/api/v2/beatmaps/{}", bm_id)) + .send() + .await? + .json::() + .await?; ctx.send(|m| { m.embed(|e| { - e.title(format!("osu! Beatmap: {} by {}", res.beatmapset.title, res.beatmapset.creator)); + e.title(format!( + "osu! Beatmap: {} by {}", + res.beatmapset.title, res.beatmapset.creator + )); e.image(res.beatmapset.covers.list2); - e.description(format!("**Link:** {}\n**Length:** {} **BPM:** {}\n**Difficulty:** {}:star:", res.url, res.total_length, res.bpm, res.difficulty_rating)); + e.description(format!( + "**Link:** {}\n**Length:** {} **BPM:** {}\n**Difficulty:** {}:star:", + res.url, res.total_length, res.bpm, res.difficulty_rating + )); e.footer(|f| { - f.text(format!("BM ID {} | BM Set ID {}\nCreated {}", res.id, res.beatmapset.id, res.beatmapset.submitted_date)); + f.text(format!( + "BM ID {} | BM Set ID {}\nCreated {}", + res.id, res.beatmapset.id, res.beatmapset.submitted_date + )); f }); e }); m - }).await?; + }) + .await?; Ok(()) } -- cgit v1.2.3