Compare commits

..

3 Commits

Author SHA1 Message Date
Xyon 54d4764458 Merge pull request 'Pivot to a different approach that only uses three fields like i should've done in the first place' (#14) from hotfix/fucking-field-limits-ffs into main
Badgey Deployment / build (push) Successful in 6m27s Details
Badgey Deployment / deploy (BADGEY) (push) Successful in 9s Details
Badgey Deployment / deploy (M5_COMPUTER) (push) Successful in 7s Details
Reviewed-on: #14
2024-10-20 11:42:38 +00:00
Xyon b2e18f23f6 Merge branch 'main' into hotfix/fucking-field-limits-ffs 2024-10-20 11:42:32 +00:00
Xyon 9c65c14bf8
Pivot to a different approach that only uses three fields like i should've done in the first place 2024-10-20 12:42:16 +01:00
1 changed files with 11 additions and 8 deletions

View File

@ -123,7 +123,7 @@ async fn rank(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
async fn leaderboard(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
let reply_handle = ctx.reply("Retrieving leaderboard, please stand by...".to_string()).await?;
let entries_per_page = 5; // Maximum due to limitation on fields per embed
let entries_per_page = 10;
let mut pages = Vec::<CreateEmbed>::new();
let leaderboard = Xp::get_leaderboard(&ctx.data().database)?;
let total = leaderboard.len();
@ -134,17 +134,20 @@ async fn leaderboard(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
.title(format!("XP Leaderboard Page {page} of {total_pages}", page=(i + 1), total_pages=&pages_needed)).to_owned();
let mut fields = Vec::new();
fields.push(("Rank", "".to_string(), true));
fields.push(("User", "".to_string(), true));
fields.push(("XP", "".to_string(), true));
let mut ranks = String::new();
let mut users = String::new();
let mut values = String::new();
leaderboard.iter().skip(i*entries_per_page).enumerate().for_each(|(i, f)| {
fields.push(("", format!("{rank}", rank=(i+1)), true));
fields.push(("", format!("<@{id}>", id=f.user_id), true));
fields.push(("", format!("{xp}", xp=f.xp_value), true));
ranks.push_str(format!("{rank}\n", rank=(i+1)).as_str());
users.push_str(format!("<@{user}>\n", user=f.user_id).as_str());
values.push_str(format!("{xp}\n", xp=f.xp_value).as_str());
});
fields.push(("Rank", &ranks, true));
fields.push(("User", &users, true));
fields.push(("XP", &values, true));
page.fields(fields);
pages.push(page);