feat: split up the committee refresh from teh regular user refresh
This commit is contained in:
parent
25fcc04287
commit
0eba54b6f2
5 changed files with 60 additions and 4 deletions
|
@ -11,6 +11,9 @@ name = "update_data"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "update_users"
|
name = "update_users"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "update_committee"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "update_minecraft"
|
name = "update_minecraft"
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,8 @@
|
||||||
"update_data" = "*:0,10,20,30,40,50";
|
"update_data" = "*:0,10,20,30,40,50";
|
||||||
# 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";
|
||||||
|
# Committee server has its own timer
|
||||||
|
"update_committee" = "*:15:00";
|
||||||
# minecraft stuff is updated at 5am
|
# minecraft stuff is updated at 5am
|
||||||
"update_minecraft" = "5:10:00";
|
"update_minecraft" = "5:10:00";
|
||||||
};
|
};
|
||||||
|
|
54
src/bin/update_committee.rs
Normal file
54
src/bin/update_committee.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use serenity::{
|
||||||
|
async_trait,
|
||||||
|
client::{Context, EventHandler},
|
||||||
|
model::gateway::{GatewayIntents, Ready},
|
||||||
|
Client,
|
||||||
|
};
|
||||||
|
use skynet_discord_bot::common::database::{db_init, get_server_config_bulk, DataBase};
|
||||||
|
use skynet_discord_bot::common::set_roles::{committee, normal};
|
||||||
|
use skynet_discord_bot::{get_config, Config};
|
||||||
|
use std::{process, sync::Arc};
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let config = get_config();
|
||||||
|
let db = match db_init(&config).await {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Intents are a bitflag, bitwise operations can be used to dictate which intents to use
|
||||||
|
let intents = GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT | GatewayIntents::GUILD_MEMBERS;
|
||||||
|
// Build our client.
|
||||||
|
let mut client = Client::builder(&config.discord_token, intents)
|
||||||
|
.event_handler(Handler {})
|
||||||
|
.await
|
||||||
|
.expect("Error creating client");
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut data = client.data.write().await;
|
||||||
|
|
||||||
|
data.insert::<Config>(Arc::new(RwLock::new(config)));
|
||||||
|
data.insert::<DataBase>(Arc::new(RwLock::new(db)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(why) = client.start().await {
|
||||||
|
println!("Client error: {:?}", why);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Handler;
|
||||||
|
#[async_trait]
|
||||||
|
impl EventHandler for Handler {
|
||||||
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
|
let ctx = Arc::new(ctx);
|
||||||
|
println!("{} is connected!", ready.user.name);
|
||||||
|
|
||||||
|
// u[date committee server
|
||||||
|
committee::check_committee(Arc::clone(&ctx)).await;
|
||||||
|
|
||||||
|
// finish up
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,9 +48,6 @@ impl EventHandler for Handler {
|
||||||
// this goes into each server and sets roles for each wolves member
|
// this goes into each server and sets roles for each wolves member
|
||||||
check_bulk(Arc::clone(&ctx)).await;
|
check_bulk(Arc::clone(&ctx)).await;
|
||||||
|
|
||||||
// u[date committee server
|
|
||||||
committee::check_committee(Arc::clone(&ctx)).await;
|
|
||||||
|
|
||||||
// finish up
|
// finish up
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ pub mod committee {
|
||||||
// ID in this is the wolves ID, so we need to get a matching discord ID (if one exists)
|
// ID in this is the wolves ID, so we need to get a matching discord ID (if one exists)
|
||||||
if let Some(x) = get_server_member_discord(db, id_wolves).await {
|
if let Some(x) = get_server_member_discord(db, id_wolves).await {
|
||||||
if let Some(member_tmp) = x.discord {
|
if let Some(member_tmp) = x.discord {
|
||||||
let values = users_roles.entry(member_tmp).or_insert(vec![committee_member]);
|
let values = users_roles.entry(member_tmp).or_insert(vec![]);
|
||||||
values.push(r.id);
|
values.push(r.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue