add leaderboard command and use username in db
parent
e6a9232661
commit
509bb6fe6e
@ -0,0 +1,22 @@
|
||||
use valence::prelude::*;
|
||||
|
||||
use redis::{Commands, Connection};
|
||||
|
||||
pub fn run(client: &mut Client, connection: &mut Connection) {
|
||||
let wins: redis::RedisResult<Vec<(String, usize)>> = connection.hgetall("wins");
|
||||
let Ok(mut wins) = wins else {
|
||||
client.send_message("Leaderboards are empty!".color(Color::RED));
|
||||
return;
|
||||
};
|
||||
|
||||
wins.sort_by_key(|(_, w)| w.clone());
|
||||
wins.reverse();
|
||||
|
||||
client.send_message("Top 10:".bold());
|
||||
|
||||
for i in 0..=(wins.len() - 1).clamp(0, 9) {
|
||||
let (username, wins) = wins[i].clone();
|
||||
|
||||
client.send_message(format!("- {} with {} win(s)", username, wins).color(Color::GOLD));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue