From 00b8c9e1453f48e19d901966a35a6389abd2d123 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 20 Jun 2024 16:38:35 +0200 Subject: [PATCH] Add link to score details and replay --- youmubot-osu/src/discord/embeds.rs | 10 ++++++++-- youmubot-osu/src/models/mod.rs | 16 ++++++++++++++++ youmubot-osu/src/models/rosu.rs | 9 +++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index 1e2c510..b7da88e 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -9,7 +9,7 @@ use serenity::{ builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter}, utils::MessageBuilder, }; -use std::time::Duration; +use std::{borrow::Cow, time::Duration}; use youmubot_prelude::*; /// Writes a number grouped in groups of 3. @@ -411,9 +411,15 @@ impl<'a> ScoreEmbedBuilder<'a> { .build(), ) .description(format!( - r#"**Played**: {} + r#"**Played**: {} {} {} {}"#, s.date.format(""), + s.link() + .map(|s| format!("[Score]({})", s).into()) + .unwrap_or(Cow::from("")), + s.replay_download_link() + .map(|s| format!("[Replay]({})", s).into()) + .unwrap_or(Cow::from("")), pp_gained.as_ref().map(|v| &v[..]).unwrap_or(""), )) .thumbnail(b.thumbnail_url()) diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index b224c2c..a44bd31 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -609,4 +609,20 @@ impl Score { pub fn accuracy(&self, _mode: Mode) -> f64 { self.server_accuracy } + + /// Gets the link to the score, if it exists. + pub fn link(&self) -> Option { + self.id + .map(|id| format!("https://osu.ppy.sh/scores/{}", id)) + } + + /// Gets the link to the replay, if it exists. + pub fn replay_download_link(&self) -> Option { + let id = self.id?; + if self.replay_available { + Some(format!("https://osu.ppy.sh/scores/{}/download", id)) + } else { + None + } + } } diff --git a/youmubot-osu/src/models/rosu.rs b/youmubot-osu/src/models/rosu.rs index 05a0de8..3f0db98 100644 --- a/youmubot-osu/src/models/rosu.rs +++ b/youmubot-osu/src/models/rosu.rs @@ -1,9 +1,6 @@ -use rosu_v2::{ - model::{ - self as rosu, - mods::{GameModIntermode, GameModsIntermode}, - }, - prelude::Acronym, +use rosu_v2::model::{ + self as rosu, + mods::{GameModIntermode, GameModsIntermode}, }; use super::*;