Merge pull request 'Fix indexes, pin to 20 per page' (#16) from hotfix/fucking-field-limits-ffs into main
Badgey Deployment / build (push) Successful in 6m7s Details
Badgey Deployment / deploy (BADGEY) (push) Successful in 6s Details
Badgey Deployment / deploy (M5_COMPUTER) (push) Successful in 6s Details

Reviewed-on: #16
This commit is contained in:
Xyon 2024-10-20 12:50:05 +00:00
commit 474c7d6b7c
1 changed files with 10 additions and 3 deletions

View File

@ -123,7 +123,7 @@ async fn rank(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
async fn leaderboard(ctx: ManifoldContext<'_>) -> ManifoldResult<()> { async fn leaderboard(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
let reply_handle = ctx.reply("Retrieving leaderboard, please stand by...".to_string()).await?; let reply_handle = ctx.reply("Retrieving leaderboard, please stand by...".to_string()).await?;
let entries_per_page = 5; let entries_per_page = 20;
let mut pages = Vec::<CreateEmbed>::new(); let mut pages = Vec::<CreateEmbed>::new();
let leaderboard = Xp::get_leaderboard(&ctx.data().database)?; let leaderboard = Xp::get_leaderboard(&ctx.data().database)?;
let total = leaderboard.len(); let total = leaderboard.len();
@ -138,8 +138,15 @@ async fn leaderboard(ctx: ManifoldContext<'_>) -> ManifoldResult<()> {
let mut users = String::new(); let mut users = String::new();
let mut values = String::new(); let mut values = String::new();
leaderboard.iter().skip(i*entries_per_page).enumerate().for_each(|(i, f)| { let offset = i*entries_per_page;
let new_rank = format!("{rank}\n", rank=(i+1));
leaderboard.iter().skip(offset).enumerate().for_each(|(j, f)| {
// cap at per-page limit
if j >= entries_per_page {
return;
}
let new_rank = format!("{rank}\n", rank=(j+1+offset));
let new_user = format!("<@{user}>\n", user=f.user_id); let new_user = format!("<@{user}>\n", user=f.user_id);
let new_value = format!("{xp}\n", xp=f.xp_value); let new_value = format!("{xp}\n", xp=f.xp_value);