From 5191dcbefcbea853d6c3b13800c841e127e04990 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 26 Feb 2024 09:41:55 +0100 Subject: [PATCH] add DTRANSLATEBOT_TOKEN env value, small fixes --- cmake/FindDPP.cmake | 4 ++-- src/main.cpp | 2 +- src/settings.cpp | 17 +++++++++-------- src/settings.h | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) 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;