From ffb7b233ab4c2c04d3756009534e03c35c6254da Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 20 Jun 2024 16:38:45 +0200 Subject: [PATCH] Update alternate download links --- youmubot-osu/src/discord/embeds.rs | 7 +++--- youmubot-osu/src/models/mod.rs | 39 ++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/youmubot-osu/src/discord/embeds.rs b/youmubot-osu/src/discord/embeds.rs index b7da88e..d320c02 100644 --- a/youmubot-osu/src/discord/embeds.rs +++ b/youmubot-osu/src/discord/embeds.rs @@ -29,12 +29,13 @@ fn beatmap_description(b: &Beatmap) -> String { MessageBuilder::new() .push_bold_line(b.approval.to_string()) .push({ - let link = b.download_link(false); + let link = b.download_link(crate::BeatmapSite::Bancho); format!( - "Download: [[Link]]({}) [[No Video]]({}?noVideo=1) [[Bloodcat]]({})", + "Download: [[Link]]({}) [[No Video]]({}?noVideo=1) [[BeatConnect]]({}) [[Chimu]]({})", link, link, - b.download_link(true), + b.download_link(crate::BeatmapSite::Beatconnect), + b.download_link(crate::BeatmapSite::Chimu), ) }) .push_line(format!(" [[Beatmapset]]({})", b.beatmapset_link())) diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index a44bd31..c0ee178 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -141,10 +141,11 @@ impl Difficulty { original_beatmap .map(|original_beatmap| { format!( - "[[Link]]({}) [[DL]]({}) [[Alt]]({}) (`{}`)", + "[[Link]]({}) [[DL]]({}) [[BC]]({}) [[Chimu]]({}) (`{}`)", original_beatmap.link(), - original_beatmap.download_link(false), - original_beatmap.download_link(true), + original_beatmap.download_link(BeatmapSite::Bancho), + original_beatmap.download_link(BeatmapSite::Beatconnect), + original_beatmap.download_link(BeatmapSite::Chimu), original_beatmap.short_link(Some(mode), Some(mods)) ) }) @@ -356,6 +357,25 @@ pub struct Beatmap { const NEW_MODE_NAMES: [&str; 4] = ["osu", "taiko", "fruits", "mania"]; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum BeatmapSite { + Bancho, + Beatconnect, + Chimu, +} + +impl BeatmapSite { + pub fn download_link(self, beatmapset: u64) -> String { + match self { + BeatmapSite::Bancho => { + format!("https://osu.ppy.sh/beatmapsets/{}/download", beatmapset) + } + BeatmapSite::Beatconnect => format!("https://beatconnect.io/b/{}", beatmapset), + BeatmapSite::Chimu => format!("https://chimu.moe/d/{}", beatmapset), + } + } +} + impl Beatmap { pub fn beatmapset_link(&self) -> String { format!( @@ -372,16 +392,9 @@ impl Beatmap { ) } - /// Returns a direct download link. If `bloodcat` is true, return the bloodcat download link. - pub fn download_link(&self, bloodcat: bool) -> String { - if bloodcat { - format!("https://bloodcat.com/osu/s/{}", self.beatmapset_id) - } else { - format!( - "https://osu.ppy.sh/beatmapsets/{}/download", - self.beatmapset_id - ) - } + /// Returns a direct download link. If `beatconnect` is true, return the beatconnect download link. + pub fn download_link(&self, site: BeatmapSite) -> String { + site.download_link(self.beatmapset_id) } /// Returns a direct link to the download (if you have supporter!)