manifold/src/config.rs

33 lines
921 B
Rust
Raw Normal View History

2023-08-30 15:53:24 +00:00
use std::collections::HashMap;
2021-11-12 12:02:22 +00:00
use std::path::PathBuf;
2022-07-17 23:25:59 +00:00
use config::Config;
2023-08-30 15:53:24 +00:00
use poise::serenity_prelude::ChannelId;
2022-07-17 23:25:59 +00:00
use crate::ManifoldResult;
2023-08-30 15:53:24 +00:00
use crate::models::fueltank::FuelTank;
2021-11-12 12:02:22 +00:00
2023-08-30 15:53:24 +00:00
#[derive(Debug, Deserialize, Serialize)]
pub struct Channels {
pub log: ChannelId,
}
#[derive(Debug, Deserialize, Serialize)]
2021-11-12 12:02:22 +00:00
pub struct ManifoldConfig {
2023-08-30 15:53:24 +00:00
pub prefix: String,
pub channels: Channels,
pub nickname: String,
pub services: HashMap<String, FuelTank>,
pub responses_file_path: PathBuf,
2021-11-12 12:02:22 +00:00
}
impl ManifoldConfig {
2023-08-30 15:53:24 +00:00
pub fn new(config_file: &String, bot_environment: &String) -> ManifoldResult<Self> {
2022-07-17 23:25:59 +00:00
let settings = Config::builder()
2023-08-30 15:53:24 +00:00
.add_source(config::File::with_name(&*format!("config/{}.{}", bot_environment.to_lowercase(), config_file)))
.add_source(config::Environment::with_prefix("manifold"))
2022-07-17 23:25:59 +00:00
.build()?;
2023-08-30 15:53:24 +00:00
Ok(settings.try_deserialize()?)
2021-11-12 12:02:22 +00:00
}
}