Skip to content

Commit

Permalink
fix: use proper pfp url for lb author icon (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn authored Aug 26, 2024
1 parent 15600da commit 103bf19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 17 additions & 11 deletions bathbot/src/commands/osu/leaderboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bathbot_macros::{command, HasMods, SlashCommand};
use bathbot_model::rosu_v2::user::User;
use bathbot_psql::model::configs::ScoreData;
use bathbot_util::{
constants::{AVATAR_URL, GENERAL_ISSUE, OSU_API_ISSUE},
constants::{GENERAL_ISSUE, OSU_API_ISSUE},
matcher,
osu::{MapIdType, ModSelection},
IntHasher, ScoreExt,
Expand Down Expand Up @@ -319,11 +319,13 @@ async fn leaderboard(orig: CommandOrigin<'_>, args: LeaderboardArgs<'_>) -> Resu
let mut calc = Context::pp(&map).mode(mode).mods(Mods::new(mods_bits));
let attrs_fut = calc.performance();

const SCORE_COUNT: usize = 100;

let scores_fut = Context::osu_scores().map_leaderboard(
map_id,
mode,
specify_mods.clone(),
100,
SCORE_COUNT as u32,
legacy_scores,
);

Expand All @@ -337,19 +339,23 @@ async fn leaderboard(orig: CommandOrigin<'_>, args: LeaderboardArgs<'_>) -> Resu

let (scores_res, user_res, attrs) = tokio::join!(scores_fut, user_fut, attrs_fut);

let mut avatar_urls = HashMap::with_capacity_and_hasher(SCORE_COUNT, IntHasher);

let mut scores: Vec<_> = match scores_res {
Ok(scores) => scores
.into_iter()
.enumerate()
.map(|(i, mut score)| {
let user = score.user.take();

LeaderboardScore::new(
score.user_id,
user.map_or_else(|| "<unknown user>".into(), |user| user.username),
score,
i + 1,
)
let username = match score.user.take() {
Some(user) => {
avatar_urls.insert(score.id, user.avatar_url);

user.username
}
None => "<unknown user>".into(),
};

LeaderboardScore::new(score.user_id, username, score, i + 1)
})
.collect(),
Err(err) => {
Expand Down Expand Up @@ -415,7 +421,7 @@ async fn leaderboard(orig: CommandOrigin<'_>, args: LeaderboardArgs<'_>) -> Resu
.await;
args.sort.push_content(&mut content);

let first_place_icon = scores.first().map(|s| format!("{AVATAR_URL}{}", s.user_id));
let first_place_icon = scores.first().and_then(|s| avatar_urls.remove(&s.score_id));

let pagination = LeaderboardPagination::builder()
.map(map)
Expand Down
6 changes: 2 additions & 4 deletions bathbot/src/commands/osu/recent/leaderboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use bathbot_macros::command;
use bathbot_model::command_fields::GameModeOption;
use bathbot_util::{
constants::{AVATAR_URL, GENERAL_ISSUE, OSU_API_ISSUE},
constants::{GENERAL_ISSUE, OSU_API_ISSUE},
matcher,
osu::ModSelection,
};
Expand Down Expand Up @@ -384,9 +384,7 @@ pub(super) async fn leaderboard(
.await;
order.push_content(&mut content);

let first_place_icon = scores
.first()
.map(|_| format!("{AVATAR_URL}{}", user.user_id()));
let first_place_icon = scores.first().map(|_| user.avatar_url().to_owned());

let pagination = LeaderboardPagination::builder()
.map(map)
Expand Down

0 comments on commit 103bf19

Please sign in to comment.