From 0e72f12b6dc8da2d948b20b81c73321b236048b1 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Wed, 19 Jun 2024 20:25:37 +0200 Subject: [PATCH] Allow more flexible inputs in embeds --- youmubot-osu/src/discord/embeds.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index 9fe9e72..256b0c2 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -343,19 +343,20 @@ impl<'a> ScoreEmbedBuilder<'a> { } else { pp.map(|v| v.1) }; - let pp_gained = s.pp.map(|full_pp| { - self.top_record - .map(|top| { - let after_pp = u.pp.unwrap(); - let effective_pp = full_pp * (0.95f64).powi(top as i32 - 1); - let before_pp = after_pp - effective_pp; - format!( - "**pp gained**: **{:.2}**pp (+**{:.2}**pp | {:.2}pp \\➡️ {:.2}pp)", - full_pp, effective_pp, before_pp, after_pp - ) - }) - .unwrap_or_else(|| format!("**pp gained**: **{:.2}**pp", full_pp)) - }); + let pp_gained = { + let effective_pp = s.effective_pp.or_else(|| { + s.pp.zip(self.top_record) + .map(|(pp, top)| pp * (0.95f64).powi(top as i32 - 1)) + }); + match (s.pp, effective_pp) { + (Some(pp), Some(epp)) => Some(format!( + "**pp gained**: **{:.2}**pp (**+{:.2}**pp)", + pp, epp + )), + (Some(pp), None) => Some(format!("**pp gained**: **{:.2}**pp", pp)), + _ => None, + } + }; let score_line = pp .map(|pp| format!("{} | {}", &score_line, pp)) .unwrap_or(score_line); @@ -370,6 +371,8 @@ impl<'a> ScoreEmbedBuilder<'a> { .unwrap_or_else(|| "".to_owned()); let world_record = self .world_record + .map(|v| v as u32) + .or(s.global_rank) .map(|v| format!(" | #{} on Global Rankings!", v)) .unwrap_or_else(|| "".to_owned()); let diff = b.difficulty.apply_mods(s.mods, stars);