Pivot to a different approach that only uses three fields like i should've done in the first place #14

Merged
xyon merged 2 commits from hotfix/fucking-field-limits-ffs into main 2024-10-20 11:42:39 +00:00
1 changed files with 11 additions and 8 deletions
Showing only changes of commit 5a2f32733c - Show all commits

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);