Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 1c7d532

Browse files
committed
fix: make plan related properties option on user struct
1 parent e5ddd85 commit 1c7d532

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/commands/aboutme.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ pub fn aboutme() {
88
Ok(user) => {
99
println!("ID: {}", user.user_id.bright_black());
1010
println!("Plan: {}", color_plan(user.plan));
11-
let end_date = user.plan_data_end;
12-
println!(
13-
"Your plan ends at: {}/{}/{} {}:{}",
14-
end_date.day(),
15-
end_date.month(),
16-
end_date.year(),
17-
end_date.hour(),
18-
end_date.minute()
19-
);
20-
println!(
21-
" Which means you have {} days left!",
22-
user.last_data_left.days.to_string().green().bold()
23-
);
11+
if let Some(end_date) = user.plan_data_end {
12+
println!(
13+
"Your plan ends at: {}/{}/{} {}:{}",
14+
end_date.day(),
15+
end_date.month(),
16+
end_date.year(),
17+
end_date.hour(),
18+
end_date.minute()
19+
);
20+
}
21+
if let Some(time_left) = user.last_data_left{
22+
println!(
23+
" Which means you have {} days left!",
24+
time_left.days.to_string().green().bold()
25+
);
26+
}
2427
println!("Memory:");
2528
println!(
2629
" Total: {}{}",

src/entities/user.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::Deserialize;
33
use super::FetchError;
44

55
#[derive(Deserialize, Debug)]
6-
pub struct UserDate {
6+
pub struct TimeLeft {
77
pub days: u32,
88
pub hours: u32,
99
pub minutes: u32,
@@ -25,9 +25,9 @@ pub struct User {
2525
pub plan: String,
2626
pub locale: String,
2727
#[serde(rename = "planDataEnd")]
28-
pub plan_data_end: chrono::DateTime<chrono::Utc>,
28+
pub plan_data_end: Option<chrono::DateTime<chrono::Utc>>,
2929
#[serde(rename = "lastDataLeft")]
30-
pub last_data_left: UserDate,
30+
pub last_data_left: Option<TimeLeft>,
3131
}
3232
#[tracing::instrument]
3333
pub fn fetch_user(token: String) -> Result<User, FetchError> {

0 commit comments

Comments
 (0)