Skip to content

Commit ac7318f

Browse files
committed
Handle both dpp 10.0.X and 10.1.X based on defined version
1 parent 4016909 commit ac7318f

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

SerialPrograms/Source/Integrations/DppIntegration/DppCommandHandler.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
2626
log_dpp(log.message, "Internal Log", log.severity);
2727
});
2828

29+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
30+
// Do nothing, owner will be set below in on_ready callback
31+
#else
2932
owner = bot.current_application_get_sync().owner;
33+
#endif
3034
auto cmd_type = GlobalSettings::instance().DISCORD->integration.command_type.get();
3135
std::string prefix = GlobalSettings::instance().DISCORD->integration.command_prefix;
3236

@@ -37,14 +41,34 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
3741
}
3842

3943
bot.on_ready([&bot, &handler, this](const ready_t&){
44+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
45+
log_dpp("Logged in as: " + bot.me.format_username() + ".", "Ready", ll_info);
46+
Handler::create_unified_commands(handler);
47+
bot.current_application_get([&](const dpp::confirmation_callback_t& cc){
48+
if (cc.is_error()){
49+
log_dpp("Error getting application details: " + cc.get_error().message, "Current App", ll_error);
50+
return;
51+
}
52+
dpp::application app = cc.get<dpp::application>();
53+
log_dpp("Application Name: " + app.name, "Current App", ll_info);
54+
log_dpp("Application ID: " + std::to_string(app.id), "Current App", ll_info);
55+
owner = app.owner;
56+
});
57+
#else
4058
log_dpp("Logged in as: " + bot.current_user_get_sync().format_username() + ".", "Ready", ll_info);
4159
Handler::create_unified_commands(handler);
60+
#endif
4261
});
4362

4463
bot.on_guild_create([&bot, this](const guild_create_t& event){
4564
try{
65+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
66+
std::string id = std::to_string(event.created.id);
67+
log_dpp("Loaded guild: " + event.created.name + " (" + id + ").", "Guild Create", ll_info);
68+
#else
4669
std::string id = std::to_string(event.created->id);
4770
log_dpp("Loaded guild: " + event.created->name + " (" + id + ").", "Guild Create", ll_info);
71+
#endif
4872
std::lock_guard<std::mutex> lg(m_count_lock);
4973
Utility::get_user_counts(bot, event);
5074
}catch (std::exception& e){
@@ -53,19 +77,35 @@ void Handler::initialize(cluster& bot, commandhandler& handler){
5377
});
5478

5579
bot.on_guild_member_add([this](const guild_member_add_t& event){
80+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
81+
std::string id = std::to_string(event.adding_guild.id);
82+
if (!user_counts.empty() && user_counts.count(id)){
83+
log_dpp("New member joined " + event.adding_guild.name + ". Incrementing member count.", "Guild Member Add", ll_info);
84+
user_counts.at(id)++;
85+
}
86+
#else
5687
std::string id = std::to_string(event.adding_guild->id);
5788
if (!user_counts.empty() && user_counts.count(id)){
5889
log_dpp("New member joined " + event.adding_guild->name + ". Incrementing member count.", "Guild Member Add", ll_info);
5990
user_counts.at(id)++;
6091
}
92+
#endif
6193
});
6294

6395
bot.on_guild_member_remove([this](const guild_member_remove_t& event){
96+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
97+
std::string id = std::to_string(event.removing_guild.id);
98+
if (!user_counts.empty() && user_counts.count(id)){
99+
log_dpp("Member left " + event.removing_guild.name + ". Decrementing member count.", "Guild Member Remove", ll_info);
100+
user_counts.at(id)--;
101+
}
102+
#else
64103
std::string id = std::to_string(event.removing_guild->id);
65104
if (!user_counts.empty() && user_counts.count(id)){
66105
log_dpp("Member left " + event.removing_guild->name + ". Decrementing member count.", "Guild Member Remove", ll_info);
67106
user_counts.at(id)--;
68107
}
108+
#endif
69109
});
70110

71111
bot.on_message_create([&handler](const message_create_t& event){

SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ void Utility::log(const std::string& message, const std::string& identity, const
3232

3333
void Utility::get_user_counts(cluster& bot, const guild_create_t& event){
3434
// Retrieve ID and exit early if we have already pulled members for this guild.
35+
#if DPP_VERSION_LONG >= 0x00100100 // (dpp version 10.1.0)
36+
auto id = std::to_string(event.created.id);
37+
if (!user_counts.empty() && user_counts.count(id)){
38+
log("Users for " + event.created.name + " already initialized.", "get_user_counts()", ll_info);
39+
return;
40+
}
41+
42+
uint32_t count = event.created.member_count;
43+
user_counts.emplace(id, count);
44+
log("User count: " + std::to_string(count) + " (" + event.created.name + ")", "get_user_counts()", ll_info);
45+
#else
3546
auto id = std::to_string(event.created->id);
3647
if (!user_counts.empty() && user_counts.count(id)){
3748
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){
4152
uint32_t count = event.created->member_count;
4253
user_counts.emplace(id, count);
4354
log("User count: " + std::to_string(count) + " (" + event.created->name + ")", "get_user_counts()", ll_info);
55+
#endif
4456
}
4557

4658
uint16_t Utility::get_button(const uint16_t& bt){

vcpkg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5bf0c55239da398b8c6f450818c9e28d36bf9966

0 commit comments

Comments
 (0)