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,
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 00:13:02 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
|
|
pub struct DatabaseConfig {
|
|
|
|
|
pub host: String,
|
|
|
|
|
pub user: String,
|
|
|
|
|
pub pass: String,
|
|
|
|
|
pub database_name: String,
|
|
|
|
|
pub port: i32,
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 15:53:24 +00:00
|
|
|
#[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>,
|
2023-09-26 00:13:02 +00:00
|
|
|
pub database: DatabaseConfig,
|
2023-08-30 15:53:24 +00:00
|
|
|
pub responses_file_path: PathBuf,
|
2024-08-26 17:36:13 +00:00
|
|
|
pub locale: String,
|
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
|
|
|
}
|
|
|
|
|
}
|