mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-25 01:30:50 +00:00
Implement score request
This commit is contained in:
parent
3e951554d7
commit
f1742664c4
5 changed files with 117 additions and 12 deletions
|
@ -13,15 +13,18 @@ impl<'de> Deserialize<'de> for Score {
|
|||
{
|
||||
let raw: raw::Score = raw::Score::deserialize(deserializer)?;
|
||||
Ok(Score {
|
||||
id: parse_from_str(&raw.score_id)?,
|
||||
username: raw.username,
|
||||
id: raw.score_id.map(parse_from_str).transpose()?,
|
||||
user_id: parse_from_str(&raw.user_id)?,
|
||||
date: parse_date(&raw.date)?,
|
||||
beatmap_id: raw.beatmap_id.map(parse_from_str).transpose()?.unwrap_or(0),
|
||||
replay_available: parse_bool(&raw.replay_available)?,
|
||||
score: parse_from_str(&raw.score)?,
|
||||
pp: parse_from_str(&raw.pp)?,
|
||||
rank: parse_from_str(&raw.rank)?,
|
||||
mods: parse_from_str(&raw.enabled_mods)?,
|
||||
mods: {
|
||||
let v: u64 = parse_from_str(&raw.enabled_mods)?;
|
||||
Mods::from_bits(v).unwrap_or(Mods::NOMOD)
|
||||
},
|
||||
count_300: parse_from_str(&raw.count300)?,
|
||||
count_100: parse_from_str(&raw.count100)?,
|
||||
count_50: parse_from_str(&raw.count50)?,
|
||||
|
|
|
@ -149,6 +149,18 @@ pub struct Beatmap {
|
|||
pub pass_count: u64,
|
||||
}
|
||||
|
||||
const NEW_MODE_NAMES: [&'static str; 4] = ["osu", "taiko", "fruits", "mania"];
|
||||
|
||||
impl Beatmap {
|
||||
/// Gets a link pointing to the beatmap, in the new format.
|
||||
pub fn link(&self) -> String {
|
||||
format!(
|
||||
"https://osu.ppy.sh/beatmapsets/{}#{}/{}",
|
||||
self.beatmapset_id, NEW_MODE_NAMES[self.mode as usize], self.beatmap_id
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UserEvent {
|
||||
pub display_html: String,
|
||||
|
@ -203,8 +215,8 @@ impl std::str::FromStr for Rank {
|
|||
type Err = String;
|
||||
fn from_str(a: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match &a.to_uppercase()[..] {
|
||||
"SS" => Rank::SS,
|
||||
"SSH" => Rank::SSH,
|
||||
"SS" | "X" => Rank::SS,
|
||||
"SSH" | "XH" => Rank::SSH,
|
||||
"S" => Rank::S,
|
||||
"SH" => Rank::SH,
|
||||
"A" => Rank::A,
|
||||
|
@ -225,11 +237,11 @@ impl fmt::Display for Rank {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Score {
|
||||
pub id: u64,
|
||||
pub username: String,
|
||||
pub id: Option<u64>, // No id if you fail
|
||||
pub user_id: u64,
|
||||
pub date: DateTime<Utc>,
|
||||
pub replay_available: bool,
|
||||
pub beatmap_id: u64,
|
||||
|
||||
pub score: u64,
|
||||
pub pp: f64,
|
||||
|
|
|
@ -78,9 +78,9 @@ pub(crate) struct UserEvent {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub(crate) struct Score {
|
||||
pub score_id: String,
|
||||
pub score_id: Option<String>,
|
||||
pub beatmap_id: Option<String>,
|
||||
pub score: String,
|
||||
pub username: String,
|
||||
pub count300: String,
|
||||
pub count100: String,
|
||||
pub count50: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue