feat: updating teh data from wolves should now also update roles for whoever changed.

This should lead to faster activations of folks who have previously linked, join a server, then get membership.

Closes #6
This commit is contained in:
silver 2023-11-25 21:15:07 +00:00
parent 7303b5782c
commit 3779222a38
4 changed files with 127 additions and 23 deletions

View file

@ -1,4 +1,12 @@
use skynet_discord_bot::{db_init, get_config, get_data::get_wolves};
use serenity::{
async_trait,
client::{Context, EventHandler},
model::gateway::{GatewayIntents, Ready},
Client,
};
use skynet_discord_bot::{db_init, get_config, get_data::get_wolves, Config, DataBase};
use std::{process, sync::Arc};
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
@ -8,6 +16,36 @@ async fn main() {
Err(_) => return,
};
// handle wolves api here
get_wolves(&db, &config).await;
// 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);
get_wolves(&ctx).await;
// finish up
process::exit(0);
}
}