Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<dpp::application>();
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<std::mutex> lg(m_count_lock);
Utility::get_user_counts(bot, event);
}catch (std::exception& e){
Expand All @@ -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){
Expand Down
12 changes: 12 additions & 0 deletions SerialPrograms/Source/Integrations/DppIntegration/DppUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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){
Expand Down