33 lines
921 B
Rust
33 lines
921 B
Rust
use std::collections::HashMap;
|
|
use std::path::PathBuf;
|
|
use config::Config;
|
|
use poise::serenity_prelude::ChannelId;
|
|
use crate::ManifoldResult;
|
|
use crate::models::fueltank::FuelTank;
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct Channels {
|
|
pub log: ChannelId,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct ManifoldConfig {
|
|
pub prefix: String,
|
|
pub channels: Channels,
|
|
pub nickname: String,
|
|
pub services: HashMap<String, FuelTank>,
|
|
pub responses_file_path: PathBuf,
|
|
}
|
|
|
|
impl ManifoldConfig {
|
|
pub fn new(config_file: &String, bot_environment: &String) -> ManifoldResult<Self> {
|
|
|
|
let settings = Config::builder()
|
|
.add_source(config::File::with_name(&*format!("config/{}.{}", bot_environment.to_lowercase(), config_file)))
|
|
.add_source(config::Environment::with_prefix("manifold"))
|
|
.build()?;
|
|
|
|
Ok(settings.try_deserialize()?)
|
|
}
|
|
}
|