Skip to content
Snippets Groups Projects
config.rs 839 B
Newer Older
Stephen D's avatar
Stephen D committed
use serde::Deserialize;
Stephen D's avatar
Stephen D committed
use std::{
	collections::{HashMap, HashSet},
	fs,
};
Stephen D's avatar
Stephen D committed

#[derive(Deserialize)]
pub struct LlamaConfig {
	pub(crate) address: String,
Stephen D's avatar
Stephen D committed
	pub(crate) port: u16,
Stephen D's avatar
Stephen D committed
	pub(crate) models: HashMap<String, String>,
Stephen D's avatar
Stephen D committed
	#[serde(default)]
	pub(crate) channels: HashSet<u64>,
Stephen D's avatar
Stephen D committed
}
Stephen D's avatar
Stephen D committed

#[derive(Deserialize)]
pub struct Config {
	pub(crate) token: String,
Stephen D's avatar
Stephen D committed
	pub(crate) llama: Option<LlamaConfig>,
Stephen D's avatar
Stephen D committed
}

pub fn get_conf() -> Config {
	let file_contents = read_conf_file();
	match toml::from_str(&file_contents) {
		Ok(x) => x,
		Err(x) => {
			panic!("Error parsing config file: {}", x);
		}
	}
}

fn read_conf_file() -> String {
	let filenames = ["config.toml", "/etc/cat_disruptor_6500/config.toml"];
	for filename in filenames.iter() {
		if let Ok(x) = fs::read_to_string(filename) {
			return x;
		}
	}

	panic!("Could not open config file");
}