use std::sync::Arc; use serenity::client::bridge::gateway::GatewayIntents; use serenity::prelude::*; use structopt::StructOpt; use discord::commands::command_framework; use discord::event_handler::Handler; use game::global_data::GlobalData; use crate::config::{Args, BotConfig}; mod config; mod discord; mod error; mod game; mod imgur; mod messages; #[tokio::main] async fn main() { let args: Args = Args::from_args(); let bot_cfg: BotConfig = BotConfig::new(&args.cfg_path).expect("Unable to parse cfg"); let mut global_data = GlobalData::new(bot_cfg.clone()); if global_data.game_state_exists() { println!("Resuming game..."); global_data .load_game_state() .expect("Unable to open saved game state."); } let mut client = Client::builder(&bot_cfg.discord_config.token) .event_handler(Handler {}) .framework(command_framework()) .intents(GatewayIntents::all()) .type_map_insert::(Arc::new(Mutex::new(global_data))) .await .expect("Err creating client"); if let Err(why) = client.start().await { println!("Client error: {:?}", why); } }