use super::Error; use async_trait::async_trait; use serde::{Deserialize, Deserializer}; #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct User { pub id: i64, pub username: String, pub profile_colour: Option, pub avatar_url: String, pub country_code: String, pub default_group: String, pub is_active: bool, pub is_bot: bool, pub is_deleted: bool, pub is_online: bool, pub is_supporter: bool, pub last_visit: Option, pub pm_friends_only: bool, pub cover_url: String, pub discord: Option, pub has_supported: bool, pub interests: Option, pub join_date: String, pub kudosu: Kudosu, pub location: Option, pub max_blocks: u64, pub max_friends: u64, pub occupation: Option, pub playmode: String, pub playstyle: Option>, pub post_count: u64, pub profile_order: Vec, pub skype: Option, pub title: Option, pub twitter: Option, pub website: Option, pub country: Country, pub cover: Cover, pub is_admin: Option, pub is_bng: Option, pub is_full_bn: Option, pub is_gmt: Option, pub is_limited_bn: Option, pub is_moderator: Option, pub is_nat: Option, pub is_restricted: Option, pub is_silenced: Option, pub statistics: UserStatistics, pub rank_history: Option, pub user_achivements: Option>, pub beatmap_playcounts_count: u64, pub favourite_beatmapset_count: u64, pub follower_count: u64, pub graveyard_beatmapset_count: u64, pub monthly_playcounts: Option>, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct CompactUser { pub avatar_url: String, pub country_code: String, pub default_group: String, pub id: u64, pub is_active: bool, pub is_bot: bool, pub is_deleted: bool, pub is_online: bool, pub is_supporter: bool, pub last_visit: Option, pub pm_friends_only: bool, pub profile_colour: Option, pub username: String, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct Kudosu { pub total: u64, pub available: u64, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct RankHistory { pub mode: String, pub data: Vec, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct MonthlyPlayCount { pub start_date: String, pub count: u64, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct UserAchivement { pub achieved_at: String, pub achievement_id: u32, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct SearchResult { pub user: SearchData, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct SearchData { pub data: Vec, pub total: u32, } #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct UserStatistics { pub grade_counts: GradeCounts, pub hit_accuracy: f32, pub is_ranked: bool, pub level: Level, pub maximum_combo: u64, pub play_count: u64, pub play_time: Option, pub pp: f32, pub global_rank: Option, pub ranked_score: u64, pub replays_watched_by_others: u64, pub total_hits: u64, pub total_score: u64, pub rank: UserRank, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct UserRank { pub global: Option, pub country: Option, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct Level { pub current: u8, pub progress: u16, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct GradeCounts { pub a: u64, pub s: u64, pub sh: u64, pub ss: u64, pub ssh: u64, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct Country { pub code: String, pub name: String, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] pub struct Cover { custom_url: Option, url: String, #[serde(default)] #[serde(deserialize_with = "parse_to_int")] id: Option, } fn parse_to_int<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let stri: Option = Option::deserialize(deserializer)?; if let Some(s) = stri { match s.parse::() { Ok(v) => return Ok(Some(v)), Err(_) => return Ok(None), } } Ok(None) } #[async_trait] pub trait UserMethods { async fn get_user<'a>(&'a mut self, id: u64, m: String) -> Result, Error>; async fn search_user<'a>(&'a mut self, name: String) -> Result, Error>; }