From 5f9037c69b6439d18942e7a5deba46ece92cd850 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 16 Sep 2023 20:03:58 +0100 Subject: [PATCH] fix: only current uses are activated --- Cargo.lock | 62 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++ src/bin/update_users.rs | 5 ++-- src/lib.rs | 11 ++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af42de3..195655f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,6 +89,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -370,6 +385,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "cipher" version = "0.2.5" @@ -1206,6 +1235,29 @@ dependencies = [ "tokio-rustls 0.24.1", ] +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.3.0" @@ -2365,6 +2417,7 @@ dependencies = [ name = "skynet_discord_bot" version = "0.1.0" dependencies = [ + "chrono", "csv", "dotenvy", "lettre", @@ -3320,6 +3373,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 8c4dd4a..5bbb73a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,9 @@ dotenvy = "0.15.7" # For sqlite sqlx = { version = "0.7.1", features = [ "runtime-tokio", "sqlite" ] } +# fancy time stuff +chrono = "0.4.26" + # handlign teh csv export from wolves csv = "1.2" diff --git a/src/bin/update_users.rs b/src/bin/update_users.rs index f44ad44..6db7513 100644 --- a/src/bin/update_users.rs +++ b/src/bin/update_users.rs @@ -7,7 +7,7 @@ use serenity::{ }, Client, }; -use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, Accounts, Config, DataBase, Servers}; +use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, Accounts, Config, DataBase, Servers, get_now_iso}; use sqlx::{Pool, Sqlite}; use std::{process, sync::Arc}; use tokio::sync::RwLock; @@ -136,10 +136,11 @@ async fn get_server_member_bulk(db: &Pool, server: &GuildId) -> Vec ? "#, ) .bind(*server.as_u64() as i64) + .bind(get_now_iso(true)) .fetch_all(db) .await .unwrap_or_default() diff --git a/src/lib.rs b/src/lib.rs index f684d00..0ce1f64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ use sqlx::{ }; use std::{env, str::FromStr, sync::Arc}; use tokio::sync::RwLock; +use chrono::{Datelike, SecondsFormat, Utc}; pub struct Config { pub skynet_server: GuildId, @@ -258,3 +259,13 @@ pub async fn get_server_config_bulk(db: &Pool) -> Vec { .await .unwrap_or_default() } + + +pub fn get_now_iso(short: bool) -> String { + let now = Utc::now(); + if short { + format!("{}-{:02}-{:02}", now.year(), now.month(), now.day()) + } else { + now.to_rfc3339_opts(SecondsFormat::Millis, true) + } +} \ No newline at end of file