From 68cf531fa7c1897314a3fcdd688eed94336ab80e Mon Sep 17 00:00:00 2001 From: 1Kill2Steal <171241044+1Git2Clone@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:55:45 +0300 Subject: [PATCH] Better level command progression display --- src/commands/level_cmds/level.rs | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/commands/level_cmds/level.rs b/src/commands/level_cmds/level.rs index 420cf42..a333553 100644 --- a/src/commands/level_cmds/level.rs +++ b/src/commands/level_cmds/level.rs @@ -1,5 +1,14 @@ use super::*; +// const LEVEL_STEPS: [f32; 15] = [ +// 6.66, 13.33, 20.0, 26.66, 33.33, 40.0, 46.66, 53.33, 59.99, 66.66, 73.33, 80.0, 86.66, 93.33, +// 100.0, +// ]; + +const LEVEL_STEPS: [f32; 14] = [ + 7.14, 14.28, 21.41, 28.56, 35.69, 42.83, 49.98, 57.12, 64.25, 71.39, 78.53, 85.67, 92.82, 99.96, +]; + /// Displays the user's level #[poise::command(slash_command, prefix_command, rename = "level")] pub async fn level( @@ -57,6 +66,28 @@ pub async fn level( let bot_user = Arc::clone(&ctx.data().bot_user); let bot_avatar = Arc::clone(&ctx.data().bot_avatar).to_string(); let percent_left_to_level_up: f32 = (xp as f32) / (level as f32); + let progress_bar: String = { + // let step: i32 = 10; + // (step..=100) + // .step_by(step as usize) + // .map(|x| { + // if percent_left_to_level_up as i32 > x { + // return "█"; + // }; + // "▒" + // }) + // .collect() + + LEVEL_STEPS + .iter() + .map(|x| { + if percent_left_to_level_up > *x { + return "█"; + } + "▒" + }) + .collect() + }; ctx.send( poise::CreateReply::default().embed( serenity::CreateEmbed::default() @@ -68,7 +99,7 @@ pub async fn level( .field("Experience Points", format!("⊱ {}", xp), false) .field( "Progress until next level", - format!("⊱ {:.2}%", percent_left_to_level_up), + format!("┊{}┊\n╰• {:.2}%", progress_bar, percent_left_to_level_up), false, ) .footer(serenity::CreateEmbedFooter::new(bot_user.tag()).icon_url(bot_avatar)),