Skip to content

Commit

Permalink
feat: save clan peak history
Browse files Browse the repository at this point in the history
  • Loading branch information
motzel committed Jun 19, 2024
1 parent 7325d59 commit 2e3bace
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/discord/worker/clan_peak.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fs::OpenOptions, io::Write};

use std::sync::Arc;

use chrono::Utc;
Expand Down Expand Up @@ -145,6 +147,36 @@ impl BlClanPeakWorker {
} else {
tracing::info!("Clan {} peak is up to date.", &clan_tag);
}

let clan_peak = ClanPeak::new(
clan_settings.get_clan_id(),
clan_tag.clone(),
clan.capture_leaderboards_count,
Utc::now(),
);
if let Ok(mut json) =
serde_json::to_string::<ClanPeak>(&clan_peak)
{
match OpenOptions::new()
.create(true)
.append(true)
.open(".storage/clan-peak-history.ndjson")
{
Ok(mut file) => {
json.push('\n');

if let Err(e) = file.write_all(json.as_bytes()) {
tracing::error!("Couldn't write clan peak history to file: {}", e);
}
}
Err(e) => {
tracing::error!(
"Couldn't create clan peak history file: {}",
e
);
}
}
}
}
Err(err) => {
tracing::error!(
Expand Down

0 comments on commit 2e3bace

Please sign in to comment.