use std::path::PathBuf; use config::Config; use poise::serenity_prelude::model::prelude::{ChannelId, MessageId, RoleId}; use crate::ManifoldResult; #[derive(Debug)] pub struct ManifoldConfig { pub environment: String, pub path: PathBuf, pub config: Config, } impl ManifoldConfig { pub fn load_config(config_file: &String, bot_environment: &String) -> ManifoldResult { let settings = Config::builder() .set_override("BotEnvironment", bot_environment.clone())? .add_source(config::File::with_name(config_file)) .add_source(config::Environment::with_prefix("MANIFOLD")) .build()?; Ok(Self { environment: bot_environment.clone(), path: PathBuf::from(config_file), config: settings }) } pub fn get_environment(&self) -> &String { &self.environment } pub fn get_path(&self) -> &PathBuf { &self.path } pub fn get_environment_mut(&mut self) -> &mut String { &mut self.environment } pub fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } pub fn get_value(&self, key: &String) -> ManifoldResult { Ok(self.config.get_string(&format!("{}{}", &self.environment, key))?) } pub fn get_role(&self, role_name: &String) -> ManifoldResult { let key = format!("{}Role", role_name); Ok(RoleId(self.get_value(&key)?.parse::()?)) } pub fn get_channel(&self, channel_name: &String) -> ManifoldResult { let key = format!("{}Channel", channel_name); Ok(ChannelId(self.get_value(&key)?.parse::()?)) } pub fn get_message(&self, message_id: &String) -> ManifoldResult { let key = format!("{}Message", message_id); Ok(MessageId(self.get_value(&key)?.parse::()?)) } }