Add link to score details and replay

This commit is contained in:
Natsu Kagami 2024-06-20 16:38:35 +02:00
parent 5cf74e425e
commit 00b8c9e145
Signed by: nki
GPG key ID: 55A032EB38B49ADB
3 changed files with 27 additions and 8 deletions

View file

@ -9,7 +9,7 @@ use serenity::{
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter}, builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
utils::MessageBuilder, utils::MessageBuilder,
}; };
use std::time::Duration; use std::{borrow::Cow, time::Duration};
use youmubot_prelude::*; use youmubot_prelude::*;
/// Writes a number grouped in groups of 3. /// Writes a number grouped in groups of 3.
@ -411,9 +411,15 @@ impl<'a> ScoreEmbedBuilder<'a> {
.build(), .build(),
) )
.description(format!( .description(format!(
r#"**Played**: {} r#"**Played**: {} {} {}
{}"#, {}"#,
s.date.format("<t:%s:R>"), s.date.format("<t:%s:R>"),
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(""), pp_gained.as_ref().map(|v| &v[..]).unwrap_or(""),
)) ))
.thumbnail(b.thumbnail_url()) .thumbnail(b.thumbnail_url())

View file

@ -609,4 +609,20 @@ impl Score {
pub fn accuracy(&self, _mode: Mode) -> f64 { pub fn accuracy(&self, _mode: Mode) -> f64 {
self.server_accuracy self.server_accuracy
} }
/// Gets the link to the score, if it exists.
pub fn link(&self) -> Option<String> {
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<String> {
let id = self.id?;
if self.replay_available {
Some(format!("https://osu.ppy.sh/scores/{}/download", id))
} else {
None
}
}
} }

View file

@ -1,9 +1,6 @@
use rosu_v2::{ use rosu_v2::model::{
model::{
self as rosu, self as rosu,
mods::{GameModIntermode, GameModsIntermode}, mods::{GameModIntermode, GameModsIntermode},
},
prelude::Acronym,
}; };
use super::*; use super::*;