Skip to content

Commit

Permalink
Better level command progression display
Browse files Browse the repository at this point in the history
  • Loading branch information
1Git2Clone committed Oct 19, 2024
1 parent 80a4e5b commit 68cf531
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/commands/level_cmds/level.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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()
Expand All @@ -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)),
Expand Down

0 comments on commit 68cf531

Please sign in to comment.