feat: split out the minecraft script so it runs at 5am instead of regularly

This commit is contained in:
silver 2024-03-05 19:55:38 +00:00
parent 7e6d892b67
commit cf2c7683d2
4 changed files with 20 additions and 8 deletions

View file

@ -11,6 +11,9 @@ name = "update_data"
[[bin]] [[bin]]
name = "update_users" name = "update_users"
[[bin]]
name = "update_minecraft"
[dependencies] [dependencies]
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] } serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

View file

@ -94,6 +94,8 @@
"update_data" = "*:0,20,40"; "update_data" = "*:0,20,40";
# groups are updated every hour, offset from teh ldap # groups are updated every hour, offset from teh ldap
"update_users" = "*:05:00"; "update_users" = "*:05:00";
# minecraft stuff is updated at 5am
"update_minecraft" = "5:10:00";
}; };
in { in {

View file

@ -0,0 +1,14 @@
use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, update_server};
#[tokio::main]
async fn main() {
let config = get_config();
let db = match db_init(&config).await {
Ok(x) => x,
Err(_) => return,
};
for server_config in get_server_config_bulk(&db).await {
update_server(server_config.server_minecraft, &db, &server_config.server, &config).await;
}
}

View file

@ -4,7 +4,7 @@ use serenity::{
model::gateway::{GatewayIntents, Ready}, model::gateway::{GatewayIntents, Ready},
Client, Client,
}; };
use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, set_roles, update_server, Config, DataBase}; use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, set_roles, Config, DataBase};
use std::{process, sync::Arc}; use std::{process, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -58,14 +58,7 @@ async fn bulk_check(ctx: Arc<Context>) {
let db = db_lock.read().await; let db = db_lock.read().await;
let config_lock = {
let data_read = ctx.data.read().await;
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
};
let config = config_lock.read().await;
for server_config in get_server_config_bulk(&db).await { for server_config in get_server_config_bulk(&db).await {
set_roles::update_server(&ctx, &server_config, &[], &vec![]).await; set_roles::update_server(&ctx, &server_config, &[], &vec![]).await;
update_server(server_config.server_minecraft, &db, &server_config.server, &config).await;
} }
} }