From e628f84a4aa25119fadc7b00e51c6636d811f7b0 Mon Sep 17 00:00:00 2001 From: pifopi Date: Tue, 2 Dec 2025 10:41:08 +0100 Subject: [PATCH] Handle both dpp 10.0.X and 10.1.X based on defined version --- .../DppIntegration/DppCommandHandler.cpp | 40 +++++++++++++++++++ .../DppIntegration/DppUtility.cpp | 12 ++++++ 2 files changed, 52 insertions(+) diff --git a/SerialPrograms/Source/Integrations/DppIntegration/DppCommandHandler.cpp b/SerialPrograms/Source/Integrations/DppIntegration/DppCommandHandler.cpp index 5169e477a8..b5c51b176a 100644 --- a/SerialPrograms/Source/Integrations/DppIntegration/DppCommandHandler.cpp +++ b/SerialPrograms/Source/Integrations/DppIntegration/DppCommandHandler.cpp @@ -26,7 +26,11 @@ void Handler::initialize(cluster& bot, commandhandler& handler){ log_dpp(log.message, "Internal Log", log.severity); }); +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + // Do nothing, owner will be set below in on_ready callback +#else owner = bot.current_application_get_sync().owner; +#endif auto cmd_type = GlobalSettings::instance().DISCORD->integration.command_type.get(); std::string prefix = GlobalSettings::instance().DISCORD->integration.command_prefix; @@ -37,14 +41,34 @@ void Handler::initialize(cluster& bot, commandhandler& handler){ } bot.on_ready([&bot, &handler, this](const ready_t&){ +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + log_dpp("Logged in as: " + bot.me.format_username() + ".", "Ready", ll_info); + Handler::create_unified_commands(handler); + bot.current_application_get([&](const dpp::confirmation_callback_t& cc){ + if (cc.is_error()){ + log_dpp("Error getting application details: " + cc.get_error().message, "Current App", ll_error); + return; + } + dpp::application app = cc.get(); + log_dpp("Application Name: " + app.name, "Current App", ll_info); + log_dpp("Application ID: " + std::to_string(app.id), "Current App", ll_info); + owner = app.owner; + }); +#else log_dpp("Logged in as: " + bot.current_user_get_sync().format_username() + ".", "Ready", ll_info); Handler::create_unified_commands(handler); +#endif }); bot.on_guild_create([&bot, this](const guild_create_t& event){ try{ +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + std::string id = std::to_string(event.created.id); + log_dpp("Loaded guild: " + event.created.name + " (" + id + ").", "Guild Create", ll_info); +#else std::string id = std::to_string(event.created->id); log_dpp("Loaded guild: " + event.created->name + " (" + id + ").", "Guild Create", ll_info); +#endif std::lock_guard lg(m_count_lock); Utility::get_user_counts(bot, event); }catch (std::exception& e){ @@ -53,19 +77,35 @@ void Handler::initialize(cluster& bot, commandhandler& handler){ }); bot.on_guild_member_add([this](const guild_member_add_t& event){ +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + std::string id = std::to_string(event.adding_guild.id); + if (!user_counts.empty() && user_counts.count(id)){ + log_dpp("New member joined " + event.adding_guild.name + ". Incrementing member count.", "Guild Member Add", ll_info); + user_counts.at(id)++; + } +#else std::string id = std::to_string(event.adding_guild->id); if (!user_counts.empty() && user_counts.count(id)){ log_dpp("New member joined " + event.adding_guild->name + ". Incrementing member count.", "Guild Member Add", ll_info); user_counts.at(id)++; } +#endif }); bot.on_guild_member_remove([this](const guild_member_remove_t& event){ +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + std::string id = std::to_string(event.removing_guild.id); + if (!user_counts.empty() && user_counts.count(id)){ + log_dpp("Member left " + event.removing_guild.name + ". Decrementing member count.", "Guild Member Remove", ll_info); + user_counts.at(id)--; + } +#else std::string id = std::to_string(event.removing_guild->id); if (!user_counts.empty() && user_counts.count(id)){ log_dpp("Member left " + event.removing_guild->name + ". Decrementing member count.", "Guild Member Remove", ll_info); user_counts.at(id)--; } +#endif }); bot.on_message_create([&handler](const message_create_t& event){ diff --git a/SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp b/SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp index 17ca8153da..74abf7eade 100644 --- a/SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp +++ b/SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp @@ -32,6 +32,17 @@ void Utility::log(const std::string& message, const std::string& identity, const void Utility::get_user_counts(cluster& bot, const guild_create_t& event){ // Retrieve ID and exit early if we have already pulled members for this guild. +#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0) + auto id = std::to_string(event.created.id); + if (!user_counts.empty() && user_counts.count(id)){ + log("Users for " + event.created.name + " already initialized.", "get_user_counts()", ll_info); + return; + } + + uint32_t count = event.created.member_count; + user_counts.emplace(id, count); + log("User count: " + std::to_string(count) + " (" + event.created.name + ")", "get_user_counts()", ll_info); +#else auto id = std::to_string(event.created->id); if (!user_counts.empty() && user_counts.count(id)){ log("Users for " + event.created->name + " already initialized.", "get_user_counts()", ll_info); @@ -41,6 +52,7 @@ void Utility::get_user_counts(cluster& bot, const guild_create_t& event){ uint32_t count = event.created->member_count; user_counts.emplace(id, count); log("User count: " + std::to_string(count) + " (" + event.created->name + ")", "get_user_counts()", ll_info); +#endif } uint16_t Utility::get_button(const uint16_t& bt){