From 18c387e1d0fc38d27a226f408269ca9307eb1037 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 11:17:04 +0100 Subject: [PATCH 1/6] Add rank to leaderboard_today --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 96d4b3a..6d89fd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,8 +126,8 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { let mut table_rows = vec![]; table_rows.push(format!( - "{1:0$} | {2:5} | {3:5}", - start_width, "Name", "Stars", "Score" + "{4:5} | {1:0$} | {2:5} | {3:5}", + start_width, "Name", "Stars", "Score", "Rank" )); table_rows.push(format!("{:-^row_size$}", "")); @@ -135,7 +135,8 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { aoch_data .today .into_iter() - .map(|x| { + .enumerate() + .map(|i, x| { let name: String = remove_emoji(&x.name.unwrap_or_else(|| ANON_USER.to_string())); let mut stars: String = String::new(); @@ -146,7 +147,7 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { stars += "*"; } - format!("{name:0$} | {stars:^5} | {1:<5}", start_width, x.score) + format!("{2:>5} | {name:0$} | {stars:^5} | {1:>5}", start_width, x.score, i+1) }) .collect::>() .as_mut(), From cf9631f227a9e899eea0850245346307d3a077d2 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 12:30:42 +0100 Subject: [PATCH 2/6] Apply formatting, add to rank ) and align stars left --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6d89fd2..e07f036 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,7 +147,12 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { stars += "*"; } - format!("{2:>5} | {name:0$} | {stars:^5} | {1:>5}", start_width, x.score, i+1) + format!( + "{2:>4}) | {name:0$} | {stars:<5} | {1:>5}", + start_width, + x.score, + i + 1 + ) }) .collect::>() .as_mut(), From cfb9003fdd5ef50593d1905ad388b9a82cc6dc79 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 12:32:29 +0100 Subject: [PATCH 3/6] formatting --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index e07f036..05dcb28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,10 +149,10 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { format!( "{2:>4}) | {name:0$} | {stars:<5} | {1:>5}", - start_width, - x.score, - i + 1 - ) + start_width, + x.score, + i + 1 + ) }) .collect::>() .as_mut(), From 643b80ad7414771e191925d5eb90b98094bfb614 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 13:11:22 +0100 Subject: [PATCH 4/6] Calculate linelength correctly And last formatting stuf --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 05dcb28..c79f229 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ -use std::cmp; use demoji_rs::remove_emoji; use poise::serenity_prelude as serenity; use serde::Deserialize; +use std::cmp; struct Data {} // User data, which is stored and accessible in all command invocations type Error = Box; @@ -121,7 +121,7 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { }) .max() .unwrap(); - let row_size: usize = start_width + 16; + let row_size: usize = start_width + 24; let row_count = 1900 / row_size; let mut table_rows = vec![]; From ec1f52cff4710847057861ae22d0474ae69ba424 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 13:47:12 +0100 Subject: [PATCH 5/6] Use rank from api endpoint --- src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c79f229..a361fd7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,8 +135,7 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { aoch_data .today .into_iter() - .enumerate() - .map(|i, x| { + .map(|x| { let name: String = remove_emoji(&x.name.unwrap_or_else(|| ANON_USER.to_string())); let mut stars: String = String::new(); @@ -151,7 +150,7 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { "{2:>4}) | {name:0$} | {stars:<5} | {1:>5}", start_width, x.score, - i + 1 + x.rank ) }) .collect::>() From d244fc3268dc7f4e3df6cd2ee8864a2cc3be3b2f Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Wed, 18 Dec 2024 13:54:43 +0100 Subject: [PATCH 6/6] Formatting --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index a361fd7..da5cc43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,9 +148,7 @@ async fn leaderboard_today(ctx: Context<'_>) -> Result<(), Error> { format!( "{2:>4}) | {name:0$} | {stars:<5} | {1:>5}", - start_width, - x.score, - x.rank + start_width, x.score, x.rank ) }) .collect::>()