64 lines
1.7 KiB
Rust
64 lines
1.7 KiB
Rust
|
use serenity::all::{ChunkGuildFilter, GuildId};
|
||
|
use serenity::{
|
||
|
async_trait,
|
||
|
client::{Context, EventHandler},
|
||
|
model::gateway::{GatewayIntents, Ready},
|
||
|
Client,
|
||
|
};
|
||
|
use skynet_discord_bot::common::database::{db_init, DataBase};
|
||
|
use skynet_discord_bot::common::wolves::cns::get_wolves;
|
||
|
use skynet_discord_bot::common::wolves::committees::get_cns;
|
||
|
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(e) => {
|
||
|
dbg!(e);
|
||
|
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 {})
|
||
|
.cache_settings(serenity::cache::Settings::default())
|
||
|
.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 the data for each individual club/soc
|
||
|
get_wolves(&ctx).await;
|
||
|
|
||
|
// get teh data for the clubs/socs committees
|
||
|
get_cns(&ctx).await;
|
||
|
|
||
|
// finish up
|
||
|
process::exit(0);
|
||
|
}
|
||
|
}
|