diff --git a/src/api/config.cpp b/src/api/config.cpp new file mode 100644 index 0000000..309ae57 --- /dev/null +++ b/src/api/config.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "config.h" + +#define CONFIG_FILE "config.json" + +bool config::is_valid_config(const json& config) { + + if (!config.contains("token")) { + std::cout << "Config file is missing \"token\" field." << std::endl; + return false; + } + + return true; +} + +json config::read_config() { + json config; + std::ifstream config_file(CONFIG_FILE); + + if (!config_file.is_open()) { + std::cout << "Failed to open config file. Please create a " << CONFIG_FILE << " file in the same directory as the executable." << std::endl; + exit(1); + } + + config_file >> config; + + if (!is_valid_config(config)) exit(1); + + return config; +} \ No newline at end of file