2022-03-20 03:12:38 +00:00
|
|
|
use std::path::Path;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use config::{Config, File};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
#[structopt(name = "WOXlf", about = "WOXlf discord bot")]
|
|
|
|
pub struct Args {
|
|
|
|
pub cfg_path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2022-03-20 23:42:50 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
|
|
|
pub struct GameConfig {
|
2022-05-28 22:31:41 +00:00
|
|
|
pub game_name: String,
|
|
|
|
pub bot_name: String,
|
2023-01-04 03:06:56 +00:00
|
|
|
pub bot_profile_pic: String,
|
2022-05-28 22:31:41 +00:00
|
|
|
pub vote_phase_name: String,
|
|
|
|
pub enemy_phase_name: String,
|
|
|
|
pub player_group_name: String,
|
2022-03-20 23:42:50 +00:00
|
|
|
pub profile_album_hash: String,
|
2023-01-04 03:06:56 +00:00
|
|
|
pub whispers_allowed: bool,
|
2022-05-28 22:31:41 +00:00
|
|
|
pub first_name: Vec<String>,
|
|
|
|
pub last_name: Vec<String>,
|
|
|
|
pub messages: MessageConfig,
|
2022-03-20 23:42:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-20 03:12:38 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
2022-05-28 22:31:41 +00:00
|
|
|
pub struct MessageConfig {
|
|
|
|
pub welcome_message: String,
|
|
|
|
pub status_message: String,
|
|
|
|
pub announcement_format: String,
|
|
|
|
pub tally_message: String,
|
|
|
|
pub vote_message: String,
|
|
|
|
pub phase_extend_message: String,
|
|
|
|
pub name_format: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
|
|
|
pub struct DiscordConfig {
|
2022-03-20 03:12:38 +00:00
|
|
|
pub token: String,
|
|
|
|
pub app_id: u64,
|
|
|
|
pub host_channel: u64,
|
2022-03-20 23:42:50 +00:00
|
|
|
pub host_webhook_id: u64,
|
2022-03-20 03:12:38 +00:00
|
|
|
pub vote_channel: u64,
|
|
|
|
pub category: u64,
|
2023-01-04 03:06:56 +00:00
|
|
|
pub guild_id: u64,
|
2022-05-28 22:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
|
|
|
pub struct BotConfig {
|
2022-03-20 23:42:50 +00:00
|
|
|
pub imgur_client_id: String,
|
2022-03-20 03:12:38 +00:00
|
|
|
pub game_state_dir: PathBuf,
|
2022-05-28 22:31:41 +00:00
|
|
|
pub discord_config: DiscordConfig,
|
|
|
|
pub game_config: Vec<GameConfig>,
|
2022-03-20 03:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BotConfig {
|
|
|
|
pub fn new(config_path: &Path) -> Result<Self, config::ConfigError> {
|
|
|
|
let cfg = Config::builder()
|
|
|
|
.add_source(File::from(config_path))
|
|
|
|
.build()?;
|
|
|
|
|
|
|
|
cfg.try_deserialize()
|
|
|
|
}
|
|
|
|
|
2022-05-28 22:31:41 +00:00
|
|
|
pub fn get_game_config(&self, game_name: &str) -> Option<GameConfig> {
|
|
|
|
let game_name = game_name.to_lowercase();
|
|
|
|
self.game_config
|
|
|
|
.iter()
|
|
|
|
.find(|g| g.game_name.to_lowercase() == game_name)
|
|
|
|
.cloned()
|
|
|
|
}
|
|
|
|
|
2022-03-20 03:12:38 +00:00
|
|
|
pub fn get_game_state_path(&self) -> PathBuf {
|
|
|
|
self.game_state_dir.join("wOxlf_data.toml")
|
|
|
|
}
|
|
|
|
}
|