wOxlf/src/config.rs

39 lines
913 B
Rust

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,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct BotConfig {
pub token: String,
pub app_id: u64,
pub host_channel: u64,
pub vote_channel: u64,
pub category: u64,
pub game_state_dir: PathBuf,
pub occupation: Vec<String>,
pub adjective: Vec<String>,
}
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()
}
pub fn get_game_state_path(&self) -> PathBuf {
self.game_state_dir.join("wOxlf_data.toml")
}
}