diff --git a/cmake/FindDPP.cmake b/cmake/FindDPP.cmake index a555a7f..55c928e 100644 --- a/cmake/FindDPP.cmake +++ b/cmake/FindDPP.cmake @@ -1,4 +1,4 @@ -find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS ${DPP_ROOT_DIR}) -find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS ${DPP_ROOT_DIR}) +find_path(DPP_INCLUDE_DIR NAMES "dpp/dpp.h" HINTS "${DPP_ROOT_DIR}") +find_library(DPP_LIBRARIES NAMES "dpp" "libdpp.a" HINTS "${DPP_ROOT_DIR}") include(FindPackageHandleStandardArgs) find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR) diff --git a/src/main.cpp b/src/main.cpp index 87bd82e..d86e55d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) { std::cout << "[Launch] Requesting supported languages..." << std::endl; if (settings.get_translator()->get_languages().empty()) { std::cerr << "[Error] Failed to initialise translateable languages" << std::endl; - return 2; + return 1; } dpp::cluster bot(settings.token(), dpp::i_default_intents | dpp::i_message_content); diff --git a/src/settings.cpp b/src/settings.cpp index a110e95..d8fb47d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -455,21 +455,24 @@ bool settings::parse(const std::string &data, bool initialize) return false; } + const std::lock_guard guard(m_mutex); auto json_token = json.find("token"); - if (json_token == json.end()) { - std::cerr << "[Error] Value token not found" << std::endl; + if (json_token != json.end()) + m_token = *json_token; + else if (char *token = getenv("DTRANSLATEBOT_TOKEN")) + m_token = token; + + if (m_token.empty()) { + std::cerr << "[Error] Discord Bot Token is not configured" << std::endl; return false; } - const std::lock_guard guard(m_mutex); - m_token = *json_token; - std::filesystem::path storage_path; auto json_storage = json.find("storage"); if (json_storage != json.end()) storage_path = std::string(*json_storage); else if (char *storagepath = getenv("DTRANSLATEBOT_STORAGE")) - storage_path = storagepath; + storage_path = storagepath; if (storage_path.empty()) storage_path = std::filesystem::current_path(); @@ -484,8 +487,6 @@ bool settings::parse(const std::string &data, bool initialize) if (!process_translator_settings(*json_translator, &m_translator)) return false; - m_avatarSize = 256; - auto json_guilds = json.find("guilds"); if (json_guilds != json.end() && json_guilds->is_object()) process_guild_settings(*json_guilds, &m_guilds, &m_webhookIds); diff --git a/src/settings.h b/src/settings.h index 7f51f16..31b71c3 100644 --- a/src/settings.h +++ b/src/settings.h @@ -61,8 +61,8 @@ namespace bot { private: mutable std::recursive_mutex m_mutex; - size_t m_externallyLockedCount; - uint16_t m_avatarSize; + size_t m_externallyLockedCount = 0; + uint16_t m_avatarSize = 256; std::shared_ptr m_database; std::vector m_guilds; std::vector m_prefLangs;