fix: only current uses are activated

This commit is contained in:
silver 2023-09-16 20:03:58 +01:00
parent 3cf298f137
commit 5f9037c69b
4 changed files with 79 additions and 2 deletions

62
Cargo.lock generated
View file

@ -89,6 +89,21 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" 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]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.75" version = "1.0.75"
@ -370,6 +385,20 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "cipher" name = "cipher"
version = "0.2.5" version = "0.2.5"
@ -1206,6 +1235,29 @@ dependencies = [
"tokio-rustls 0.24.1", "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]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"
@ -2365,6 +2417,7 @@ dependencies = [
name = "skynet_discord_bot" name = "skynet_discord_bot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"csv", "csv",
"dotenvy", "dotenvy",
"lettre", "lettre",
@ -3320,6 +3373,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 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]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"

View file

@ -24,6 +24,9 @@ dotenvy = "0.15.7"
# For sqlite # For sqlite
sqlx = { version = "0.7.1", features = [ "runtime-tokio", "sqlite" ] } sqlx = { version = "0.7.1", features = [ "runtime-tokio", "sqlite" ] }
# fancy time stuff
chrono = "0.4.26"
# handlign teh csv export from wolves # handlign teh csv export from wolves
csv = "1.2" csv = "1.2"

View file

@ -7,7 +7,7 @@ use serenity::{
}, },
Client, 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 sqlx::{Pool, Sqlite};
use std::{process, sync::Arc}; use std::{process, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -136,10 +136,11 @@ async fn get_server_member_bulk(db: &Pool<Sqlite>, server: &GuildId) -> Vec<Acco
r#" r#"
SELECT * SELECT *
FROM accounts FROM accounts
WHERE server = ? AND discord IS NOT NULL WHERE server = ? AND discord IS NOT NULL AND expiry > ?
"#, "#,
) )
.bind(*server.as_u64() as i64) .bind(*server.as_u64() as i64)
.bind(get_now_iso(true))
.fetch_all(db) .fetch_all(db)
.await .await
.unwrap_or_default() .unwrap_or_default()

View file

@ -14,6 +14,7 @@ use sqlx::{
}; };
use std::{env, str::FromStr, sync::Arc}; use std::{env, str::FromStr, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use chrono::{Datelike, SecondsFormat, Utc};
pub struct Config { pub struct Config {
pub skynet_server: GuildId, pub skynet_server: GuildId,
@ -258,3 +259,13 @@ pub async fn get_server_config_bulk(db: &Pool<Sqlite>) -> Vec<Servers> {
.await .await
.unwrap_or_default() .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)
}
}