From 3221aacd95aec6118f465329fa113152eab6212f Mon Sep 17 00:00:00 2001 From: Data Date: Sun, 27 Nov 2022 17:03:40 -0800 Subject: [PATCH 1/3] Add settings struct and move wvw_detailed bool to it. Add gw2bot settings, load and save them from ini. --- arcdps_uploader/Uploader.cpp | 17 ++++++++++++----- arcdps_uploader/Uploader.h | 10 +++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/arcdps_uploader/Uploader.cpp b/arcdps_uploader/Uploader.cpp index 863db24..031b447 100644 --- a/arcdps_uploader/Uploader.cpp +++ b/arcdps_uploader/Uploader.cpp @@ -9,6 +9,8 @@ using json = nlohmann::json; const char* INI_SECTION_SETTINGS = "Settings"; const char* INI_WVW_DETAILED_SETTING = "WvW_Detailed"; +const char* INI_GW2BOT_ENABLED = "GW2Bot_Enabled"; +const char* INI_GW2BOT_KEY = "GW2Bot_Key"; inline auto initStorage(const std::string& path) { @@ -56,7 +58,7 @@ static std::unique_ptr storage; Uploader::Uploader(fs::path data_path, std::optional custom_log_path) : is_open(false) , in_combat(false) - , wvw_detailed_enabled(false) + , settings{false, false, ""} , ini_enabled(true) { //INI @@ -65,7 +67,10 @@ Uploader::Uploader(fs::path data_path, std::optional custom_log_path) SI_Error error = ini.LoadFile(ini_path.string().c_str()); if (error == SI_OK) { LOG_F(INFO, "Loaded INI file"); - wvw_detailed_enabled = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, false); + settings.wvw_detailed_enabled = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, false); + settings.gw2bot_enabled = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_ENABLED, false); + settings.gw2bot_key = ini.GetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, ""); + settings.gw2bot_key.reserve(128); } //Sqlite Database @@ -146,7 +151,9 @@ Uploader::~Uploader() LOG_F(INFO, "Uploader destructor begin..."); // Save our settings if we previously loaded/created an ini file if (ini_enabled) { - ini.SetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, wvw_detailed_enabled); + ini.SetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, settings.wvw_detailed_enabled); + ini.SetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_ENABLED, settings.gw2bot_enabled); + ini.SetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, settings.gw2bot_key.c_str()); ini.SaveFile(ini_path.string().c_str()); } @@ -566,7 +573,7 @@ uintptr_t Uploader::imgui_tick() if (ImGui::TreeNode("Other")) { - ImGui::Checkbox("Enable detailed WvW reports", &wvw_detailed_enabled); + ImGui::Checkbox("Enable detailed WvW reports", &settings.wvw_detailed_enabled); if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); @@ -955,7 +962,7 @@ void Uploader::upload_thread_loop() { params.AddParameter({ "userToken", userToken.value }); } - if (wvw_detailed_enabled) { + if (settings.wvw_detailed_enabled) { params.AddParameter({ "detailedwvw", "true" }); } diff --git a/arcdps_uploader/Uploader.h b/arcdps_uploader/Uploader.h index 0cb6cb4..e3aa250 100644 --- a/arcdps_uploader/Uploader.h +++ b/arcdps_uploader/Uploader.h @@ -45,12 +45,21 @@ struct Webhook char filter_buf[128]; }; +struct Settings +{ + bool wvw_detailed_enabled; + bool gw2bot_enabled; + std::string gw2bot_key; +}; + class Uploader { bool ini_enabled; fs::path ini_path; CSimpleIniA ini; + Settings settings; + fs::path log_path; std::vector logs; std::future ft_file_list; @@ -58,7 +67,6 @@ class Uploader std::deque upload_queue; std::vector> ft_uploads; - bool wvw_detailed_enabled; std::vector userTokens; UserToken userToken; std::vector webhooks; From d96bb0fd4ad335e58673e0c82c65633b076394c5 Mon Sep 17 00:00:00 2001 From: Data Date: Sun, 27 Nov 2022 17:56:43 -0800 Subject: [PATCH 2/3] Add Old Lion's Court ids and fix EOD strike categories. --- revtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revtc b/revtc index b8d37ea..823dad1 160000 --- a/revtc +++ b/revtc @@ -1 +1 @@ -Subproject commit b8d37eab609dd121e0db7eb8bf1cb67f88b0ea42 +Subproject commit 823dad17f2e21e34ac097704469d56adba93af4f From af609083f2b36b5581aff43c1f98dacae413898c Mon Sep 17 00:00:00 2001 From: Data Date: Sun, 27 Nov 2022 22:35:06 -0800 Subject: [PATCH 3/3] Add GW2Bot integration gui elements. Upload loop now calls check_gw2bot to post logs if integration is enabled. --- arcdps_uploader/Uploader.cpp | 98 ++++++++++++++++++++++++++++++++++-- arcdps_uploader/Uploader.h | 4 +- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/arcdps_uploader/Uploader.cpp b/arcdps_uploader/Uploader.cpp index 031b447..e929e89 100644 --- a/arcdps_uploader/Uploader.cpp +++ b/arcdps_uploader/Uploader.cpp @@ -11,6 +11,7 @@ const char* INI_SECTION_SETTINGS = "Settings"; const char* INI_WVW_DETAILED_SETTING = "WvW_Detailed"; const char* INI_GW2BOT_ENABLED = "GW2Bot_Enabled"; const char* INI_GW2BOT_KEY = "GW2Bot_Key"; +const char* INI_GW2BOT_SUCCESS_ONLY = "GW2Bot_Success_Only"; inline auto initStorage(const std::string& path) { @@ -58,7 +59,7 @@ static std::unique_ptr storage; Uploader::Uploader(fs::path data_path, std::optional custom_log_path) : is_open(false) , in_combat(false) - , settings{false, false, ""} + , settings{false, false, "", false} , ini_enabled(true) { //INI @@ -69,8 +70,9 @@ Uploader::Uploader(fs::path data_path, std::optional custom_log_path) LOG_F(INFO, "Loaded INI file"); settings.wvw_detailed_enabled = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, false); settings.gw2bot_enabled = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_ENABLED, false); - settings.gw2bot_key = ini.GetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, ""); - settings.gw2bot_key.reserve(128); + const char* pv = ini.GetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, ""); + strcpy(settings.gw2bot_key, pv); + settings.gw2bot_success_only = ini.GetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_SUCCESS_ONLY, false); } //Sqlite Database @@ -153,7 +155,8 @@ Uploader::~Uploader() if (ini_enabled) { ini.SetBoolValue(INI_SECTION_SETTINGS, INI_WVW_DETAILED_SETTING, settings.wvw_detailed_enabled); ini.SetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_ENABLED, settings.gw2bot_enabled); - ini.SetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, settings.gw2bot_key.c_str()); + ini.SetValue(INI_SECTION_SETTINGS, INI_GW2BOT_KEY, settings.gw2bot_key); + ini.SetBoolValue(INI_SECTION_SETTINGS, INI_GW2BOT_SUCCESS_ONLY, settings.gw2bot_success_only); ini.SaveFile(ini_path.string().c_str()); } @@ -571,6 +574,51 @@ uintptr_t Uploader::imgui_tick() ImGui::TreePop(); } + if (ImGui::TreeNode("GW2Bot")) + { + ImGui::Checkbox("GW2Bot Integration Enabled", &settings.gw2bot_enabled); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Post logs to GW2Bot for use with the EVTC Automation commands."); + ImGui::EndTooltip(); + } + + ImGui::SameLine(); + ImGui::TextDisabled("(?)"); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted("Use the /evtc_automation autopost add_destination command to have GW2Bot post logs to a Discord channel.\nSee gw2bot.info/commands for details."); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } + + if (settings.gw2bot_enabled) + { + ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() - ImGui::CalcTextSize("EVTC Api Key").x - 5); + ImGui::InputText("EVTC Api Key", settings.gw2bot_key, sizeof(settings.gw2bot_key)); + ImGui::PopItemWidth(); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Use GW2Bot's /evtc_automation api_key command to generate an API key."); + ImGui::EndTooltip(); + } + + ImGui::Checkbox("Clears only", &settings.gw2bot_success_only); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("Only post clears/successful logs to GW2Bot."); + ImGui::EndTooltip(); + } + } + + ImGui::TreePop(); + } + if (ImGui::TreeNode("Other")) { ImGui::Checkbox("Enable detailed WvW reports", &settings.wvw_detailed_enabled); @@ -798,6 +846,43 @@ void Uploader::check_webhooks(int log_id) } } +void Uploader::check_gw2bot(int log_id) +{ + if (!settings.gw2bot_enabled) return; + + auto log = storage->get_pointer(log_id); + if (log) + { + bool process = true; + if (!log->success && settings.gw2bot_success_only) process = false; + + if (process) { + LOG_F(INFO, "Posting to GW2Bot: %s", log->permalink.c_str()); + auto gw2bot_future = std::async(std::launch::async, [this](const char* key, Log log) { + cpr::Response response; + response = cpr::Post( + cpr::Url{"https://api.gw2bot.info/v1/evtc/notification"}, + cpr::Header{ + {"accept", "application/json"}, + {"Authorization", "Bearer " + std::string(key)}, + {"Content-Type", "application/json"}, + }, + cpr::Body{"{\"dpsreport_url\": \"" + log.permalink + "\"}"} + ); + if (response.status_code != 201) { + StatusMessage status; + status.msg = "GW2Bot Error: " + response.text; + { + std::lock_guard lk(ts_msg_mutex); + thread_status_messages.push_back(status); + } + } + LOG_F(INFO, "GW2Bot response: %s", response.text.c_str()); + }, settings.gw2bot_key, *log); + } + } +} + void Uploader::start_async_refresh_log_list() { LOG_F(INFO, "Starting Async Log Refresh"); using namespace sqlite_orm; @@ -1019,7 +1104,10 @@ void Uploader::upload_thread_loop() { try { storage->update(*log); - if (log->uploaded && !log->error) check_webhooks(log->id); + if (log->uploaded && !log->error) { + check_webhooks(log->id); + check_gw2bot(log->id); + }; } catch (std::system_error e) { diff --git a/arcdps_uploader/Uploader.h b/arcdps_uploader/Uploader.h index e3aa250..c571a76 100644 --- a/arcdps_uploader/Uploader.h +++ b/arcdps_uploader/Uploader.h @@ -49,7 +49,8 @@ struct Settings { bool wvw_detailed_enabled; bool gw2bot_enabled; - std::string gw2bot_key; + char gw2bot_key[256]; + bool gw2bot_success_only; }; class Uploader @@ -96,6 +97,7 @@ class Uploader void create_log_table(Log& l); void check_webhooks(int log_id); + void check_gw2bot(int log_id); void start_async_refresh_log_list();