lichess_api/model/users/
mod.rs

1pub mod activity;
2pub mod autocomplete;
3pub mod by_id;
4pub mod crosstable;
5pub mod leaderboard;
6pub mod live_streamers;
7pub mod note;
8pub mod performance;
9pub mod public;
10pub mod rating_history;
11pub mod status;
12pub mod top_10;
13
14use std::collections::HashMap;
15
16use crate::model::{LightUser, Title};
17use serde::{Deserialize, Serialize};
18use serde_with::skip_serializing_none;
19
20#[skip_serializing_none]
21#[derive(Clone, Debug, Deserialize, Serialize)]
22#[serde(rename_all = "camelCase")]
23pub struct UserExtended {
24    #[serde(flatten)]
25    pub user: User,
26    pub url: String,
27    pub playing: Option<String>,
28    pub count: Count,
29    pub streaming: Option<bool>,
30    pub streamer: Option<UserStreamer>,
31    pub followable: Option<bool>,
32    pub following: Option<bool>,
33    pub blocking: Option<bool>,
34}
35
36#[derive(Clone, Debug, Serialize, Deserialize)]
37#[serde(rename_all = "camelCase")]
38pub struct Count {
39    pub all: u32,
40    pub rated: u32,
41    pub ai: u32,
42    pub draw: u32,
43    pub draw_h: u32,
44    pub loss: u32,
45    pub loss_h: u32,
46    pub win: u32,
47    pub win_h: u32,
48    pub bookmark: u32,
49    pub playing: u32,
50    pub import: u32,
51    pub me: u32,
52}
53
54#[skip_serializing_none]
55#[derive(Clone, Debug, Deserialize, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct User {
58    pub id: String,
59    pub username: String,
60    pub perfs: Perfs,
61    pub created_at: i64,
62    pub disabled: Option<bool>,
63    pub tos_violation: Option<bool>,
64    pub profile: Option<Profile>,
65    pub seen_at: i64,
66    pub patron: Option<bool>,
67    pub verified: Option<bool>,
68    pub play_time: PlayTime,
69    pub title: Option<Title>,
70    pub flair: Option<String>,
71}
72
73#[skip_serializing_none]
74#[derive(Clone, Debug, Deserialize, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct Perfs {
77    pub chess960: Option<Perf>,
78    pub atomic: Option<Perf>,
79    pub racing_kings: Option<Perf>,
80    pub ultra_bullet: Option<Perf>,
81    pub blitz: Option<Perf>,
82    pub king_of_the_hill: Option<Perf>,
83    pub bullet: Option<Perf>,
84    pub correspondence: Option<Perf>,
85    pub horde: Option<Perf>,
86    pub puzzle: Option<Perf>,
87    pub classical: Option<Perf>,
88    pub rapid: Option<Perf>,
89    pub three_check: Option<Perf>,
90    pub antichess: Option<Perf>,
91    pub crazyhouse: Option<Perf>,
92    pub storm: Option<Storm>,
93    pub racer: Option<Storm>,
94    pub streak: Option<Storm>,
95}
96
97#[derive(Clone, Debug, Deserialize, Serialize)]
98pub struct Perf {
99    pub games: u32,
100    pub rating: u32,
101    pub rd: u32,
102    pub prog: i32,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub prov: Option<bool>,
105}
106
107#[derive(Clone, Debug, Deserialize, Serialize)]
108pub struct Storm {
109    pub runs: u32,
110    pub score: u32,
111}
112
113#[derive(Clone, Debug, Deserialize, Serialize)]
114pub struct PlayTime {
115    pub total: u32,
116    pub tv: u32,
117}
118
119#[derive(Clone, Debug, Deserialize, Serialize)]
120#[serde(rename_all = "camelCase")]
121pub struct Profile {
122    pub flag: Option<String>,
123    pub location: Option<String>,
124    pub bio: Option<String>,
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub real_name: Option<String>,
127    pub fide_rating: Option<u32>,
128    pub uscf_rating: Option<u32>,
129    pub ecf_rating: Option<u32>,
130    pub cfc_rating: Option<u32>,
131    pub rcf_rating: Option<u32>,
132    pub dsb_rating: Option<u32>,
133    pub links: Option<String>,
134}
135
136#[derive(Clone, Debug, Deserialize, Serialize)]
137pub struct Stream {
138    pub service: String,
139    pub status: String,
140    pub lang: String,
141}
142
143#[skip_serializing_none]
144#[derive(Clone, Debug, Deserialize, Serialize)]
145pub struct UserStreamer {
146    pub twitch: Option<StreamerChannel>,
147    #[serde(rename = "youTube")]
148    pub youtube: Option<StreamerChannel>,
149}
150
151#[derive(Clone, Debug, Deserialize, Serialize)]
152pub struct StreamerChannel {
153    pub channel: String,
154}
155
156#[skip_serializing_none]
157#[derive(Clone, Debug, Deserialize, Serialize)]
158pub struct Streamer {
159    pub name: String,
160    pub headline: String,
161    pub description: Option<String>,
162    #[serde(rename = "youTube")]
163    pub youtube: Option<String>,
164    pub twitch: Option<String>,
165    pub image: String,
166}
167
168#[derive(Clone, Debug, Deserialize, Serialize)]
169pub struct StreamingUser {
170    #[serde(flatten)]
171    pub user: LightUser,
172    pub stream: Stream,
173    pub streamer: Streamer,
174}
175
176#[derive(Clone, Debug, Deserialize, Serialize)]
177pub struct Matchup {
178    pub users: HashMap<String, f64>,
179
180    #[serde(rename = "nbGames")]
181    pub game_count: u32,
182}
183
184#[skip_serializing_none]
185#[derive(Clone, Debug, Deserialize, Serialize)]
186pub struct Crosstable {
187    #[serde(flatten)]
188    pub all_time: Matchup,
189    pub matchup: Option<Matchup>,
190}
191
192#[skip_serializing_none]
193#[derive(Clone, Debug, Deserialize, Serialize)]
194pub struct UserNote {
195    pub from: LightUser,
196    pub to: LightUser,
197    pub text: String,
198    pub date: u64,
199}
200
201#[derive(Clone, Debug, Deserialize, Serialize)]
202pub struct LeaderboardPerf {
203    pub rating: u32,
204    pub progress: i32,
205}
206
207// Lichess returns { perfs: { "{PerfType}": { rating: u32, progress: u32} } },
208// this therfore more accurate than a struct with `variant_name: Perf` for each variant.
209#[skip_serializing_none]
210#[derive(Clone, Debug, Deserialize, Serialize)]
211#[serde(rename_all = "camelCase")]
212pub enum LeaderboardPerfs {
213    Bullet(LeaderboardPerf),
214    Blitz(LeaderboardPerf),
215    Rapid(LeaderboardPerf),
216    Classical(LeaderboardPerf),
217    UltraBullet(LeaderboardPerf),
218    Chess960(LeaderboardPerf),
219    Crazyhouse(LeaderboardPerf),
220    Antichess(LeaderboardPerf),
221    Atomic(LeaderboardPerf),
222    Horde(LeaderboardPerf),
223    KingOfTheHill(LeaderboardPerf),
224    RacingKings(LeaderboardPerf),
225    ThreeCheck(LeaderboardPerf),
226}
227
228impl LeaderboardPerfs {
229    pub fn into_perf(self) -> LeaderboardPerf {
230        match self {
231            Self::Bullet(perf)
232            | Self::Blitz(perf)
233            | Self::Rapid(perf)
234            | Self::Classical(perf)
235            | Self::UltraBullet(perf)
236            | Self::Chess960(perf)
237            | Self::Crazyhouse(perf)
238            | Self::Antichess(perf)
239            | Self::Atomic(perf)
240            | Self::Horde(perf)
241            | Self::KingOfTheHill(perf)
242            | Self::RacingKings(perf)
243            | Self::ThreeCheck(perf) => perf,
244        }
245    }
246}
247
248impl From<LeaderboardPerfs> for LeaderboardPerf {
249    fn from(perfs: LeaderboardPerfs) -> LeaderboardPerf {
250        perfs.into_perf()
251    }
252}
253
254#[skip_serializing_none]
255#[derive(Clone, Debug, Deserialize, Serialize)]
256#[serde(rename_all = "camelCase")]
257pub struct Player {
258    pub id: String,
259    pub username: String,
260    pub perfs: LeaderboardPerfs,
261    pub title: Option<Title>,
262    pub patron: Option<bool>,
263    pub online: Option<bool>,
264}
265
266pub type PerfTop10 = Vec<TopUser>;
267
268#[derive(Clone, Debug, Serialize, Deserialize)]
269#[serde(rename_all = "camelCase")]
270pub struct Top10s {
271    pub bullet: PerfTop10,
272    pub blitz: PerfTop10,
273    pub rapid: PerfTop10,
274    pub classical: PerfTop10,
275    pub ultra_bullet: PerfTop10,
276    pub chess960: PerfTop10,
277    pub crazyhouse: PerfTop10,
278    pub antichess: PerfTop10,
279    pub atomic: PerfTop10,
280    pub horde: PerfTop10,
281    pub king_of_the_hill: PerfTop10,
282    pub racing_kings: PerfTop10,
283    pub three_check: PerfTop10,
284}
285
286#[skip_serializing_none]
287#[derive(Clone, Debug, Deserialize, Serialize)]
288pub struct TopUser {
289    pub id: String,
290    pub username: String,
291    pub perfs: std::collections::HashMap<String, TopUserPerf>,
292    pub title: Option<Title>,
293    pub patron: Option<bool>,
294    pub online: Option<bool>,
295}
296
297#[derive(Clone, Debug, Deserialize, Serialize)]
298pub struct TopUserPerf {
299    pub rating: u32,
300    pub progress: i32,
301}
302
303#[derive(Clone, Debug, Serialize, Deserialize)]
304pub struct Leaderboard {
305    pub users: Vec<Player>,
306}