2022-03-20 03:12:38 +00:00
|
|
|
use std::sync::Arc;
|
2022-03-05 21:35:02 +00:00
|
|
|
|
2022-03-06 17:03:49 +00:00
|
|
|
use serenity::prelude::*;
|
2022-03-05 21:35:02 +00:00
|
|
|
use structopt::StructOpt;
|
|
|
|
|
2023-01-09 03:13:31 +00:00
|
|
|
use discord::command_framework;
|
2022-03-20 15:46:40 +00:00
|
|
|
use discord::event_handler::Handler;
|
2022-03-20 03:12:38 +00:00
|
|
|
use game::global_data::GlobalData;
|
|
|
|
|
|
|
|
use crate::config::{Args, BotConfig};
|
2023-01-08 20:44:11 +00:00
|
|
|
use crate::game::listener::Listeners;
|
2023-01-08 23:23:50 +00:00
|
|
|
use crate::game::role::Role;
|
2022-03-20 03:12:38 +00:00
|
|
|
|
|
|
|
mod config;
|
|
|
|
mod discord;
|
|
|
|
mod error;
|
|
|
|
mod game;
|
2022-03-20 23:42:50 +00:00
|
|
|
mod imgur;
|
2022-05-28 22:31:41 +00:00
|
|
|
mod messages;
|
2022-03-20 03:12:38 +00:00
|
|
|
|
2022-03-05 21:35:02 +00:00
|
|
|
#[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");
|
|
|
|
|
2022-03-06 17:03:49 +00:00
|
|
|
let mut global_data = GlobalData::new(bot_cfg.clone());
|
|
|
|
|
2022-03-20 03:12:38 +00:00
|
|
|
if global_data.game_state_exists() {
|
|
|
|
println!("Resuming game...");
|
|
|
|
global_data
|
|
|
|
.load_game_state()
|
|
|
|
.expect("Unable to open saved game state.");
|
2022-03-06 17:03:49 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 23:23:50 +00:00
|
|
|
let mut listeners = Listeners::default();
|
|
|
|
Role::Spy.register_role_listener(&mut listeners);
|
2023-02-15 01:46:19 +00:00
|
|
|
Role::WolfAgent.register_role_listener(&mut listeners);
|
2023-01-08 23:23:50 +00:00
|
|
|
|
2023-01-04 03:06:56 +00:00
|
|
|
let mut client = Client::builder(&bot_cfg.discord_config.token, GatewayIntents::all())
|
2022-03-05 21:35:02 +00:00
|
|
|
.event_handler(Handler {})
|
|
|
|
.framework(command_framework())
|
2022-03-06 17:03:49 +00:00
|
|
|
.type_map_insert::<GlobalData>(Arc::new(Mutex::new(global_data)))
|
2023-01-08 23:23:50 +00:00
|
|
|
.type_map_insert::<Listeners>(Arc::new(Mutex::new(listeners)))
|
2022-03-05 21:35:02 +00:00
|
|
|
.await
|
|
|
|
.expect("Err creating client");
|
|
|
|
|
|
|
|
if let Err(why) = client.start().await {
|
|
|
|
println!("Client error: {:?}", why);
|
|
|
|
}
|
|
|
|
}
|