Implement user score

This commit is contained in:
Natsu Kagami 2024-02-13 23:42:55 +01:00
parent da39e6ed25
commit 05ade8370d
Signed by: nki
GPG key ID: 55A032EB38B49ADB
3 changed files with 20 additions and 17 deletions

View file

@ -117,8 +117,6 @@ impl Client {
) -> Result<Vec<Score>, Error> {
let mut r = UserScoreRequestBuilder::new(u, user);
f(&mut r);
let res: Vec<raw::Score> = r.build(self).await?.json().await?;
let res = vec_try_into(res)?;
Ok(res)
r.build(self).await
}
}

View file

@ -288,7 +288,7 @@ pub mod builders {
r.await
}
})?
.unwrap_or(vec![]);
.ok_or_else(|| error!("beatmap or user not found"))?;
Ok(scores.into_iter().map(|v| v.into()).collect())
}
}
@ -325,18 +325,23 @@ pub mod builders {
self
}
pub(crate) async fn build(&self, client: &Client) -> Result<Response> {
Ok(client
.build_request(match self.score_type {
UserScoreType::Best => "https://osu.ppy.sh/api/get_user_best",
UserScoreType::Recent => "https://osu.ppy.sh/api/get_user_recent",
})
.await?
.query(&self.user.to_query())
.query(&self.mode.to_query())
.query(&self.limit.map(|v| ("limit", v.to_string())).to_query())
.send()
.await?)
pub(crate) async fn build(self, client: &Client) -> Result<Vec<models::Score>> {
let scores = handle_not_found({
let mut r = client.rosu.user_scores(self.user);
r = match self.score_type {
UserScoreType::Recent => r.recent(),
UserScoreType::Best => r.best(),
};
if let Some(mode) = self.mode {
r = r.mode(mode.into());
}
if let Some(limit) = self.limit {
r = r.limit(limit as usize);
}
r.await
})?
.ok_or_else(|| error!("user not found"))?;
Ok(scores.into_iter().map(|v| v.into()).collect())
}
}
}

View file

@ -23,7 +23,7 @@ pub use pagination::{paginate, paginate_fn, paginate_reply, paginate_reply_fn, P
pub use async_trait::async_trait;
/// Re-export the anyhow errors
pub use anyhow::{Error, Result};
pub use anyhow::{anyhow as error, bail, Error, Result};
pub use debugging_ok::OkPrint;
/// Re-export useful future and stream utils