From 487f8647baf676ff682a5a1e6ab7d30d09b0d364 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 25 Feb 2025 15:58:11 +0100 Subject: [PATCH] osu: add passes_only flag to recent command --- youmubot-osu/src/discord/commands.rs | 6 +++++- youmubot-osu/src/request.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs index c21019d..22e8db9 100644 --- a/youmubot-osu/src/discord/commands.rs +++ b/youmubot-osu/src/discord/commands.rs @@ -119,6 +119,7 @@ async fn recent( #[min = 1] #[max = 50] index: Option, + #[description = "Only include passed scores"] passes_only: Option, #[description = "Score listing style"] style: Option, #[description = "Game mode"] mode: Option, #[description = "osu! username"] username: Option, @@ -127,6 +128,7 @@ async fn recent( let env = ctx.data().osu_env(); let args = arg_from_username_or_discord(username, discord_name); let style = style.unwrap_or(ScoreListStyle::Table); + let include_fails = !passes_only.unwrap_or(false); let args = ListingArgs::from_params(env, index, style, mode, args, ctx.author().id).await?; @@ -134,7 +136,9 @@ async fn recent( let osu_client = &env.client; let plays = osu_client - .user_recent(UserID::ID(args.user.id), |f| f.mode(args.mode).limit(50)) + .user_recent(UserID::ID(args.user.id), |f| { + f.mode(args.mode).include_fails(include_fails).limit(50) + }) .await?; handle_listing(ctx, plays, args, |_, b| b, "recent").await diff --git a/youmubot-osu/src/request.rs b/youmubot-osu/src/request.rs index 20b0313..2947276 100644 --- a/youmubot-osu/src/request.rs +++ b/youmubot-osu/src/request.rs @@ -248,6 +248,7 @@ pub mod builders { user: UserID, mode: Option, limit: Option, + include_fails: bool, } impl UserScoreRequestBuilder { @@ -257,6 +258,7 @@ pub mod builders { user, mode: None, limit: None, + include_fails: true, } } @@ -270,11 +272,16 @@ pub mod builders { self } + pub fn include_fails(&mut self, include_fails: bool) -> &mut Self { + self.include_fails = include_fails; + self + } + pub(crate) async fn build(self, client: &OsuClient) -> Result> { let scores = handle_not_found({ let mut r = client.rosu.user_scores(self.user); r = match self.score_type { - UserScoreType::Recent => r.recent().include_fails(true), + UserScoreType::Recent => r.recent().include_fails(self.include_fails), UserScoreType::Best => r.best(), UserScoreType::Pin => r.pinned(), };