From c28cad0718e87dc6bdc28cb2ca44edef0d5f22ac Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Sat, 15 Feb 2025 17:02:17 +0100 Subject: [PATCH] osu: small redundancy cleanups --- youmubot-osu/src/discord/commands.rs | 38 +++++----------------------- youmubot-osu/src/discord/mod.rs | 26 +++++++++++-------- youmubot-osu/src/models/mod.rs | 3 +++ 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs index f82b684..f07ebee 100644 --- a/youmubot-osu/src/discord/commands.rs +++ b/youmubot-osu/src/discord/commands.rs @@ -183,15 +183,7 @@ pub async fn save( .clone() .send( CreateReply::default() - .content(format!( - "To set your osu username to **{}**, please make your most recent play \ - be the following map: `/b/{}` in **{}** mode! \ - It does **not** have to be a pass, and **NF** can be used! \ - React to this message with 👌 within 5 minutes when you're done!", - u.username, - score.beatmap_id, - mode.as_str_new_site() - )) + .content(save_request_message(&u.username, score.beatmap_id, mode)) .embed(beatmap_embed(&beatmap, mode, Mods::NOMOD, &info)) .components(vec![beatmap_components(mode, ctx.guild_id())]), ) @@ -349,10 +341,7 @@ async fn beatmap( }; ctx.send( CreateReply::default() - .content(format!( - "Information for beatmap `{}`", - beatmap.short_link(mode, &mods) - )) + .content(format!("Information for {}", beatmap.mention(mode, &mods))) .embed(beatmap_embed( &beatmap, mode.unwrap_or(beatmap.mode), @@ -372,11 +361,7 @@ async fn beatmap( let b0 = &vec[0]; let msg = ctx .clone() - .reply(format!( - "Information for beatmapset [`/s/{}`](<{}>)", - b0.beatmapset_id, - b0.beatmapset_link() - )) + .reply(format!("Information for {}", b0.beatmapset_mention())) .await? .into_message() .await?; @@ -475,17 +460,9 @@ async fn check( }; let display = if beatmaps.len() == 1 { - format!( - "[{}](<{}>)", - beatmaps[0].0.short_link(None, Mods::NOMOD), - beatmaps[0].0.link() - ) + beatmaps[0].0.mention(None, Mods::NOMOD) } else { - format!( - "[/s/{}](<{}>)", - beatmaps[0].0.beatmapset_id, - beatmaps[0].0.beatmapset_link() - ) + beatmaps[0].0.beatmapset_mention() }; let ordering = sort.unwrap_or_default(); @@ -602,10 +579,9 @@ async fn leaderboard( let beatmap = &bm.0; if scores.is_empty() { ctx.reply(format!( - "No scores have been recorded in **{}** on [`{}`]({}).", + "No scores have been recorded in **{}** on {}.", guild.name, - beatmap.short_link(mode, Mods::NOMOD), - beatmap.link() + beatmap.mention(mode, Mods::NOMOD), )) .await?; return Ok(()); diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index a39670d..8f3316e 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -257,15 +257,7 @@ pub async fn save(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult .send_message( &ctx, CreateMessage::new() - .content(format!( - "To set your osu username to **{}**, please make your most recent play \ - be the following map: `/b/{}` in **{}** mode! \ - It does **not** have to be a pass, and **NF** can be used! \ - React to this message with 👌 within 5 minutes when you're done!", - u.username, - score.beatmap_id, - mode.as_str_new_site() - )) + .content(save_request_message(&u.username, score.beatmap_id, mode)) .embed(beatmap_embed(&beatmap, mode, Mods::NOMOD, &info)) .components(vec![beatmap_components(mode, msg.guild_id)]), ) @@ -274,6 +266,18 @@ pub async fn save(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult Ok(()) } +pub(crate) fn save_request_message(username: &str, beatmap_id: u64, mode: Mode) -> String { + format!( + "To set your osu username to **{}**, please make your most recent play \ + be the following map: `/b/{}` in **{}** mode! \ + It does **not** have to be a pass, and **NF** can be used! \ + React to this message with 👌 within 5 minutes when you're done!", + username, + beatmap_id, + mode.as_str_new_site() + ) +} + pub(crate) async fn find_save_requirements( env: &OsuEnv, username: String, @@ -943,9 +947,9 @@ pub async fn check(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul .reply( &ctx, format!( - "Here are the scores by `{}` on `{}`!", + "Here are the scores by `{}` on {}!", &user.username, - bm.short_link(&mods) + bm.0.mention(Some(bm.1), &mods) ), ) .await?; diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index 86a3a0e..753df0b 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -457,6 +457,9 @@ impl Beatmap { self.mode_link(override_mode), ) } + pub fn beatmapset_mention(&self) -> String { + format!("[/s/{}](<{}>)", self.beatmapset_id, self.beatmapset_link()) + } /// Link to the cover image of the beatmap. pub fn cover_url(&self) -> String {