mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-21 01:38:55 +00:00
Simplify beatmap embed information
This commit is contained in:
parent
6659bdda57
commit
3e0d21693f
2 changed files with 38 additions and 64 deletions
|
@ -7,14 +7,6 @@ use chrono::Utc;
|
||||||
use serenity::{builder::CreateEmbed, utils::MessageBuilder};
|
use serenity::{builder::CreateEmbed, utils::MessageBuilder};
|
||||||
use youmubot_prelude::*;
|
use youmubot_prelude::*;
|
||||||
|
|
||||||
fn format_mode(actual: Mode, original: Mode) -> String {
|
|
||||||
if actual == original {
|
|
||||||
format!("{}", actual)
|
|
||||||
} else {
|
|
||||||
format!("{} (converted)", actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn beatmap_embed<'a>(
|
pub fn beatmap_embed<'a>(
|
||||||
b: &'_ Beatmap,
|
b: &'_ Beatmap,
|
||||||
m: Mode,
|
m: Mode,
|
||||||
|
@ -45,18 +37,8 @@ pub fn beatmap_embed<'a>(
|
||||||
.icon_url(format!("https://a.ppy.sh/{}", b.creator_id))
|
.icon_url(format!("https://a.ppy.sh/{}", b.creator_id))
|
||||||
})
|
})
|
||||||
.url(b.link())
|
.url(b.link())
|
||||||
.thumbnail(format!("https://b.ppy.sh/thumb/{}l.jpg", b.beatmapset_id))
|
|
||||||
.image(b.cover_url())
|
.image(b.cover_url())
|
||||||
.color(0xffb6c1)
|
.color(0xffb6c1)
|
||||||
.field(
|
|
||||||
"Star Difficulty",
|
|
||||||
format!(
|
|
||||||
"{:.2}⭐",
|
|
||||||
info.map(|v| v.stars as f64).unwrap_or(b.difficulty.stars)
|
|
||||||
),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.fields(Some(("Mods", mods, true)).filter(|_| mods != Mods::NOMOD))
|
|
||||||
.fields(info.map(|info| {
|
.fields(info.map(|info| {
|
||||||
(
|
(
|
||||||
"Calculated pp",
|
"Calculated pp",
|
||||||
|
@ -67,23 +49,8 @@ pub fn beatmap_embed<'a>(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
.field(
|
.field("Information", diff.format_info(m, mods, b), false)
|
||||||
"Length",
|
|
||||||
MessageBuilder::new()
|
|
||||||
.push_bold_safe(Duration(diff.total_length))
|
|
||||||
.push(" (")
|
|
||||||
.push_bold_safe(Duration(diff.drain_length))
|
|
||||||
.push(" drain)")
|
|
||||||
.build(),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.field("Circle Size", format!("{:.1}", diff.cs), true)
|
|
||||||
.field("Approach Rate", format!("{:.1}", diff.ar), true)
|
|
||||||
.field("Overall Difficulty", format!("{:.1}", diff.od), true)
|
|
||||||
.field("HP Drain", format!("{:.1}", diff.hp), true)
|
|
||||||
.field("BPM", diff.bpm.round(), true)
|
|
||||||
.fields(b.difficulty.max_combo.map(|v| ("Max combo", v, true)))
|
.fields(b.difficulty.max_combo.map(|v| ("Max combo", v, true)))
|
||||||
.field("Mode", format_mode(m, b.mode), true)
|
|
||||||
.fields(b.source.as_ref().map(|v| ("Source", v, true)))
|
.fields(b.source.as_ref().map(|v| ("Source", v, true)))
|
||||||
.field(
|
.field(
|
||||||
"Tags",
|
"Tags",
|
||||||
|
@ -153,7 +120,6 @@ pub fn beatmapset_embed<'a>(
|
||||||
"https://osu.ppy.sh/beatmapsets/{}",
|
"https://osu.ppy.sh/beatmapsets/{}",
|
||||||
b.beatmapset_id,
|
b.beatmapset_id,
|
||||||
))
|
))
|
||||||
// .thumbnail(format!("https://b.ppy.sh/thumb/{}l.jpg", b.beatmapset_id))
|
|
||||||
.image(format!(
|
.image(format!(
|
||||||
"https://assets.ppy.sh/beatmaps/{}/covers/cover.jpg",
|
"https://assets.ppy.sh/beatmaps/{}/covers/cover.jpg",
|
||||||
b.beatmapset_id
|
b.beatmapset_id
|
||||||
|
@ -178,14 +144,6 @@ pub fn beatmapset_embed<'a>(
|
||||||
.push_bold(&b.genre)
|
.push_bold(&b.genre)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.field(
|
|
||||||
"Length",
|
|
||||||
MessageBuilder::new()
|
|
||||||
.push_bold_safe(Duration(b.difficulty.total_length))
|
|
||||||
.build(),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.field("BPM", b.difficulty.bpm.round(), true)
|
|
||||||
.fields(b.source.as_ref().map(|v| ("Source", v, false)))
|
.fields(b.source.as_ref().map(|v| ("Source", v, false)))
|
||||||
.field(
|
.field(
|
||||||
"Tags",
|
"Tags",
|
||||||
|
@ -212,27 +170,7 @@ pub fn beatmapset_embed<'a>(
|
||||||
.fields(bs.iter().rev().take(MAX_DIFFS).rev().map(|b: &Beatmap| {
|
.fields(bs.iter().rev().take(MAX_DIFFS).rev().map(|b: &Beatmap| {
|
||||||
(
|
(
|
||||||
format!("[{}]", b.difficulty_name),
|
format!("[{}]", b.difficulty_name),
|
||||||
MessageBuilder::new()
|
b.difficulty.format_info(m.unwrap_or(b.mode), Mods::NOMOD, b),
|
||||||
.push(format!(
|
|
||||||
"[[Link]]({}) (`{}`)",
|
|
||||||
b.link(),
|
|
||||||
b.short_link(m, None)
|
|
||||||
))
|
|
||||||
.push(", ")
|
|
||||||
.push_bold(format!("{:.2}⭐", b.difficulty.stars))
|
|
||||||
.push(", ")
|
|
||||||
.push_bold_line(format_mode(m.unwrap_or(b.mode), b.mode))
|
|
||||||
.push("CS")
|
|
||||||
.push_bold(format!("{:.1}", b.difficulty.cs))
|
|
||||||
.push(", AR")
|
|
||||||
.push_bold(format!("{:.1}", b.difficulty.ar))
|
|
||||||
.push(", OD")
|
|
||||||
.push_bold(format!("{:.1}", b.difficulty.od))
|
|
||||||
.push(", HP")
|
|
||||||
.push_bold(format!("{:.1}", b.difficulty.hp))
|
|
||||||
.push(", ⌛ ")
|
|
||||||
.push_bold(format!("{}", Duration(b.difficulty.drain_length)))
|
|
||||||
.build(),
|
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -2,12 +2,14 @@ use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use youmubot_prelude::Duration as YoumuDuration;
|
||||||
|
|
||||||
pub mod mods;
|
pub mod mods;
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
pub(crate) mod raw;
|
pub(crate) mod raw;
|
||||||
|
|
||||||
pub use mods::Mods;
|
pub use mods::Mods;
|
||||||
|
use serenity::utils::MessageBuilder;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub enum ApprovalStatus {
|
pub enum ApprovalStatus {
|
||||||
|
@ -118,6 +120,40 @@ impl Difficulty {
|
||||||
|
|
||||||
diff
|
diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Format the difficulty info into a short summary.
|
||||||
|
pub fn format_info(&self, mode: Mode, mods: Mods, original_beatmap: &Beatmap) -> String {
|
||||||
|
MessageBuilder::new()
|
||||||
|
.push(format!(
|
||||||
|
"[[Link]]({}) (`{}`)",
|
||||||
|
original_beatmap.link(),
|
||||||
|
original_beatmap.short_link(Some(mode), Some(mods))
|
||||||
|
))
|
||||||
|
.push(", ")
|
||||||
|
.push_bold(format!("{:.2}⭐", self.stars))
|
||||||
|
.push(", ")
|
||||||
|
.push_bold_line(format_mode(mode, original_beatmap.mode))
|
||||||
|
.push("CS")
|
||||||
|
.push_bold(format!("{:.1}", self.cs))
|
||||||
|
.push(", AR")
|
||||||
|
.push_bold(format!("{:.1}", self.ar))
|
||||||
|
.push(", OD")
|
||||||
|
.push_bold(format!("{:.1}", self.od))
|
||||||
|
.push(", HP")
|
||||||
|
.push_bold(format!("{:.1}", self.hp))
|
||||||
|
.push(format!(", BPM**{}**", self.bpm))
|
||||||
|
.push(", ⌛ ")
|
||||||
|
.push_bold(format!("{}", YoumuDuration(self.drain_length)))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_mode(actual: Mode, original: Mode) -> String {
|
||||||
|
if actual == original {
|
||||||
|
format!("{}", actual)
|
||||||
|
} else {
|
||||||
|
format!("{} (converted)", actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Serialize)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue