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

View file

@ -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<Sqlite>, server: &GuildId) -> Vec<Acco
r#"
SELECT *
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(get_now_iso(true))
.fetch_all(db)
.await
.unwrap_or_default()

View file

@ -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<Sqlite>) -> Vec<Servers> {
.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)
}
}