1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//! Models for the endpoint "User Info".
//!
//! About the endpoint "User Info",
//! see the [API document](https://tetr.io/about/api/#usersuser).
use crate::{model::prelude::*, util::deserialize_from_non_str_to_none};
/// A struct that describes a user in detail.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct User {
/// The user's internal ID.
#[serde(rename = "_id")]
pub id: UserId,
/// The user's username.
pub username: String,
/// The user's role.
pub role: Role,
/// When the user account was created.
/// If not set, this account was created before join dates were recorded.
#[serde(rename = "ts")]
pub created_at: Option<Timestamp>,
/// If this user is a bot, the bot's operator.
#[serde(rename = "botmaster")]
pub bot_master: Option<String>,
/// The user's badges
pub badges: Vec<Badge>,
/// The user's XP in points.
pub xp: f64,
/// The amount of online games played by this user.
/// If the user has chosen to hide this statistic, it will be -1.
#[serde(rename = "gamesplayed")]
pub play_count: i32,
/// The amount of online games won by this user.
/// If the user has chosen to hide this statistic, it will be -1.
#[serde(rename = "gameswon")]
pub won_count: i32,
/// The amount of seconds this user spent playing,both on- and offline.
/// If the user has chosen to hide this statistic, it will be -1.
#[serde(rename = "gametime")]
pub play_time: f64,
/// The user's ISO 3166-1 country code, or `None` if hidden/unknown.
/// Some vanity flags exist.
pub country: Option<String>,
/// Whether the user currently has a bad standing (recently banned).
#[serde(rename = "badstanding")]
#[serde(default)] // If the field is missing, it is false.
pub is_badstanding: bool,
/// Whether the user is currently supporting TETR.IO <3
#[serde(rename = "supporter")]
#[serde(default)] // If the field is missing, it is false.
pub is_supporter: bool,
/// An indicator of their total amount supported,
/// between 0 and 4 inclusive.
pub supporter_tier: u8,
/// This user's avatar ID.
/// We can get their avatar at
/// `https://tetr.io/user-content/avatars/{ USERID }.jpg?rv={ AVATAR_REVISION }`.
pub avatar_revision: Option<u64>,
/// his user's banner ID.
/// We can get their banner at
/// `https://tetr.io/user-content/banners/{ USERID }.jpg?rv={ BANNER_REVISION }`.
/// Ignore this field if the user is not a supporter.
pub banner_revision: Option<u64>,
/// This user's "About Me" section.
/// Ignore this field if the user is not a supporter.
pub bio: Option<String>,
/// This user's third party connections.
pub connections: Connections,
/// The amount of players who have added this user to their friends list.
///
/// ***The API document does not say this field is optional.**
pub friend_count: Option<u32>,
// This user's distinguishment banner.
pub distinguishment: Option<Distinguishment>,
/// This user's featured achievements.
/// Up to three integers which correspond to Achievement IDs.
pub achievements: Vec<i32>,
/// This user's Achievement Rating.
#[serde(rename = "ar")]
pub achievement_rating: i32,
/// The breakdown of the source of this user's Achievement Rating.
#[serde(rename = "ar_counts")]
pub achievement_rating_counts: AchievementRatingCounts,
}
impl User {
impl_for_xp!();
impl_for_username!();
impl_for_role!();
impl_for_account_created_at!();
/// Whether the user has any badges.
pub fn has_badge(&self) -> bool {
!self.badges.is_empty()
}
/// Returns the number of badges the user has.
pub fn badge_count(&self) -> usize {
self.badges.len()
}
impl_for_avatar_revision!();
impl_for_banner_revision!();
impl_for_country!();
}
impl AsRef<User> for User {
fn as_ref(&self) -> &Self {
self
}
}
/// A user's badge.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct Badge {
/// The badge's internal ID,
/// and the filename of the badge icon
/// (all PNGs within `/res/badges/`).
/// Note that badge IDs may include forward slashes.
/// Please do not encode them!
/// Follow the folder structure.
pub id: BadgeId,
/// The badge's group ID.
/// If multiple badges have the same group ID, they are rendered together.
pub group: Option<String>,
/// The badge's label, shown when hovered.
pub label: String,
/// Extra flavor text for the badge, shown when hovered.
///
/// ***The API document does not say this field is optional.**
pub desc: Option<String>,
/// The badge's timestamp, if shown.
///
/// Why it uses `deserialize_with` attribute?
/// See [this issue](https://github.com/Rinrin0413/tetr-ch-rs/issues/4).
#[serde(
rename = "ts",
deserialize_with = "deserialize_from_non_str_to_none",
default
)]
pub received_at: Option<Timestamp>,
}
impl Badge {
impl_for_id_badge_id!();
impl_for_received_at!();
}
impl AsRef<Badge> for Badge {
fn as_ref(&self) -> &Self {
self
}
}
/// A user's third party connections.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct Connections {
/// This user's connection to Discord.
///
/// - `id`: Discord ID.
/// - `username`: Discord username.
/// - `display_username`: Same as `username`.
pub discord: Option<Connection>,
/// This user's connection to Twitch.
///
/// - `id`: Twitch user ID.
/// - `username`: Twitch username (as used in the URL).
/// - `display_username`: Twitch display name (may include Unicode).
pub twitch: Option<Connection>,
/// This user's connection to X
/// (kept in the API as twitter for readability).
///
/// - `id`: X user ID.
/// - `username`: X handle (as used in the URL).
/// - `display_username`: X display name (may include Unicode).
pub twitter: Option<Connection>,
/// This user's connection to Reddit.
///
/// - `id`: Reddit user ID.
/// - `username`: Reddit username.
/// - `display_username`: Same as `username`.
pub reddit: Option<Connection>,
/// This user's connection to YouTube.
///
/// - `id`: YouTube user ID (as used in the URL).
/// - `username`: YouTube display name.
/// - `display_username`: Same as `username`.
pub youtube: Option<Connection>,
/// This user's connection to Steam.
///
/// - `id`: SteamID.
/// - `username`: Steam display name.
/// - `display_username`: Same as `username`.
pub steam: Option<Connection>,
}
impl AsRef<Connections> for Connections {
fn as_ref(&self) -> &Self {
self
}
}
/// A user's connection.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct Connection {
/// This user's user ID on the service.
pub id: String,
/// This user's username on the service.
pub username: String,
/// This user's display username on the service.
pub display_username: String,
}
impl AsRef<Connection> for Connection {
fn as_ref(&self) -> &Self {
self
}
}
/// A user's distinguishment banner.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct Distinguishment {
/// The type of distinguishment banner.
#[serde(rename = "type")]
pub _type: String,
/// The detail of distinguishment banner.
///
/// ***The API document does not say about this field.**
pub detail: Option<String>,
/// The header of distinguishment banner.
///
/// ***The API document does not say about this field.**
pub header: Option<String>,
/// The footer of distinguishment banner.
///
/// ***The API document does not say about this field.**
pub footer: Option<String>,
}
impl AsRef<Distinguishment> for Distinguishment {
fn as_ref(&self) -> &Self {
self
}
}
/// A breakdown of the source of a user's Achievement Rating.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct AchievementRatingCounts {
/// The amount of ranked Bronze achievements this user has.
#[serde(rename = "1")]
pub bronze: Option<u32>,
/// The amount of ranked Silver achievements this user has.
#[serde(rename = "2")]
pub silver: Option<u32>,
/// The amount of ranked Gold achievements this user has.
#[serde(rename = "3")]
pub gold: Option<u32>,
/// The amount of ranked Platinum achievements this user has.
#[serde(rename = "4")]
pub platinum: Option<u32>,
/// The amount of ranked Diamond achievements this user has.
#[serde(rename = "5")]
pub diamond: Option<u32>,
/// The amount of ranked Issued achievements this user has.
#[serde(rename = "100")]
pub issued: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 100 with.
#[serde(rename = "t100")]
pub top100: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 50 with.
#[serde(rename = "t50")]
pub top50: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 25 with.
#[serde(rename = "t25")]
pub top25: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 10 with.
#[serde(rename = "t10")]
pub top10: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 5 with.
#[serde(rename = "t5")]
pub top5: Option<u32>,
/// The amount of competitive achievements this user has ranked into the top 3 with.
#[serde(rename = "t3")]
pub top3: Option<u32>,
}
impl AsRef<AchievementRatingCounts> for AchievementRatingCounts {
fn as_ref(&self) -> &Self {
self
}
}