diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index 65684a1..ecacc4f 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -192,10 +192,9 @@ pub async fn save(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult let scores = client .user_best(UserID::ID(u.id), |f| f.mode(*mode)) .await?; - match scores.into_iter().choose(&mut rand::thread_rng()) { - Some(v) => return Ok(Some((v, *mode))), - None => (), - }; + if let Some(v) = scores.into_iter().choose(&mut rand::thread_rng()) { + return Ok(Some((v, *mode))); + } } Ok(None) } diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index d8e4a45..088e66d 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -430,15 +430,7 @@ impl Beatmap { } #[derive(Clone, Debug)] -pub enum UserEvent { - Rank(UserEventRank), - OtherV1 { - display_html: String, - date: DateTime, - epic_factor: u8, - }, - OtherV2(rosu_v2::model::recent_event::RecentEvent), -} +pub struct UserEvent(pub rosu_v2::model::recent_event::RecentEvent); /// Represents a "achieved rank #x on beatmap" event. #[derive(Clone, Debug, Serialize, Deserialize)] @@ -452,8 +444,29 @@ pub struct UserEventRank { impl UserEvent { /// Try to parse the event into a "rank" event. pub fn to_event_rank(&self) -> Option { - match self { - UserEvent::Rank(r) => Some(r.clone()), + match &self.0.event_type { + rosu_v2::model::recent_event::EventType::Rank { + grade: _, + rank, + mode, + beatmap, + user: _, + } => Some(UserEventRank { + beatmap_id: { + beatmap + .url + .trim_start_matches("/b/") + .trim_end_matches("?m=0") + .trim_end_matches("?m=1") + .trim_end_matches("?m=2") + .trim_end_matches("?m=3") + .parse::() + .unwrap() + }, + rank: *rank as u16, + mode: (*mode).into(), + date: rosu::time_to_utc(self.0.created_at), + }), _ => None, } } diff --git a/youmubot-osu/src/models/mods.rs b/youmubot-osu/src/models/mods.rs index f20013a..3d8858c 100644 --- a/youmubot-osu/src/models/mods.rs +++ b/youmubot-osu/src/models/mods.rs @@ -7,7 +7,6 @@ bitflags::bitflags! { /// The mods available to osu! #[derive(std::default::Default, Serialize, Deserialize)] pub struct Mods: u64 { - const NOMOD = 0; const NF = 1 << 0; const EZ = 1 << 1; const TD = 1 << 2; @@ -38,10 +37,6 @@ bitflags::bitflags! { const KEY3 = 1 << 27; const KEY2 = 1 << 28; const SCOREV2 = 1 << 29; - const TOUCH_DEVICE = Self::TD.bits; - const NOVIDEO = Self::TD.bits; /* never forget */ - const SPEED_CHANGING = Self::DT.bits | Self::HT.bits | Self::NC.bits; - const MAP_CHANGING = Self::HR.bits | Self::EZ.bits | Self::SPEED_CHANGING.bits; // Made up flags const LAZER = 1 << 59; @@ -49,6 +44,16 @@ bitflags::bitflags! { } } +impl Mods { + pub const NOMOD: Mods = Mods::empty(); + pub const TOUCH_DEVICE: Mods = Self::TD; + pub const NOVIDEO: Mods = Self::TD; /* never forget */ + pub const SPEED_CHANGING: Mods = + Mods::from_bits_truncate(Self::DT.bits | Self::HT.bits | Self::NC.bits); + pub const MAP_CHANGING: Mods = + Mods::from_bits_truncate(Self::HR.bits | Self::EZ.bits | Self::SPEED_CHANGING.bits); +} + const MODS_WITH_NAMES: &[(Mods, &str)] = &[ (Mods::NF, "NF"), (Mods::EZ, "EZ"), diff --git a/youmubot-osu/src/models/rosu.rs b/youmubot-osu/src/models/rosu.rs index 92f7b2c..1361422 100644 --- a/youmubot-osu/src/models/rosu.rs +++ b/youmubot-osu/src/models/rosu.rs @@ -23,7 +23,7 @@ impl ApprovalStatus { } } -fn time_to_utc(s: time::OffsetDateTime) -> DateTime { +pub(super) fn time_to_utc(s: time::OffsetDateTime) -> DateTime { chrono::DateTime::from_timestamp(s.unix_timestamp(), 0).unwrap() } @@ -107,31 +107,7 @@ impl User { impl From for UserEvent { fn from(value: rosu::recent_event::RecentEvent) -> Self { - match value.event_type { - rosu::recent_event::EventType::Rank { - grade: _, - rank, - mode, - beatmap, - user: _, - } => Self::Rank(UserEventRank { - beatmap_id: { - beatmap - .url - .trim_start_matches("/b/") - .trim_end_matches("?m=0") - .trim_end_matches("?m=1") - .trim_end_matches("?m=2") - .trim_end_matches("?m=3") - .parse::() - .unwrap() - }, - rank: rank as u16, - mode: mode.into(), - date: time_to_utc(value.created_at), - }), - _ => Self::OtherV2(value), - } + Self(value) } }