Skip to content

Commit 95b7f32

Browse files
authored
Merge branch 'PokemonAutomation:main' into main
2 parents 44b4165 + 3a5e79d commit 95b7f32

File tree

5 files changed

+68
-16
lines changed

5 files changed

+68
-16
lines changed

Common/Cpp/Options/CheckboxDropdownDatabase.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,36 @@ struct FlagEnumEntry{
3232

3333
template <typename FlagEnum>
3434
class CheckboxDropdownDatabase{
35-
using FlagEnumEntry = FlagEnumEntry<FlagEnum>;
35+
using Entry = FlagEnumEntry<FlagEnum>;
3636

3737
public:
3838
CheckboxDropdownDatabase() = default;
39-
CheckboxDropdownDatabase(std::initializer_list<FlagEnumEntry> list){
39+
CheckboxDropdownDatabase(std::initializer_list<Entry> list){
4040
for (auto iter = list.begin(); iter != list.end(); ++iter){
4141
add(iter->value, std::move(iter->slug), std::move(iter->display));
4242
}
4343
}
4444

4545
// Warning, these functions do not have strong exception safety!
4646
// If these throw, this class will be in a bad state.
47-
void add(FlagEnumEntry entry){
48-
FlagEnumEntry& e = m_list.emplace_back(std::move(entry));
47+
void add(Entry entry){
48+
Entry& e = m_list.emplace_back(std::move(entry));
4949

5050
auto ret = m_slug_to_enum.emplace(e.slug, &e);
5151
if (!ret.second){
5252
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Enum Slug: " + e.slug);
5353
}
5454
}
5555
void add(FlagEnum value, std::string slug, std::string display){
56-
add(FlagEnumEntry{value, std::move(slug), std::move(display)});
56+
add(Entry{value, std::move(slug), std::move(display)});
5757
}
5858

5959

6060
public:
6161
size_t size() const{
6262
return m_list.size();
6363
}
64-
const FlagEnumEntry& operator[](size_t index) const{
64+
const Entry& operator[](size_t index) const{
6565
return m_list[index];
6666
}
6767
const FlagEnum* find_slug(const std::string& slug) const{
@@ -82,8 +82,8 @@ class CheckboxDropdownDatabase{
8282

8383

8484
private:
85-
std::vector<FlagEnumEntry> m_list;
86-
std::map<std::string, const FlagEnumEntry*> m_slug_to_enum;
85+
std::vector<Entry> m_list;
86+
std::map<std::string, const Entry*> m_slug_to_enum;
8787
};
8888

8989

Common/Cpp/Options/CheckboxDropdownOption.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ class CheckboxDropdownBase : public ConfigOption{
4646

4747
template <typename FlagEnum>
4848
class CheckboxDropdownCell : public CheckboxDropdownBase{
49-
using CheckboxDropdownDatabase = CheckboxDropdownDatabase<FlagEnum>;
49+
using Database = CheckboxDropdownDatabase<FlagEnum>;
5050

5151
public:
5252
CheckboxDropdownCell(
5353
std::string label,
54-
const CheckboxDropdownDatabase& database,
54+
const Database& database,
5555
LockMode lock_while_running,
5656
FlagEnum default_value
5757
);
5858
CheckboxDropdownCell(
5959
std::string label,
60-
const CheckboxDropdownDatabase& database,
60+
const Database& database,
6161
LockMode lock_while_running,
6262
FlagEnum default_value, FlagEnum current_value
6363
);
6464
CheckboxDropdownCell(
6565
std::string label,
66-
CheckboxDropdownDatabase&& database,
66+
Database&& database,
6767
LockMode lock_while_running,
6868
FlagEnum default_value
6969
) = delete;
7070
CheckboxDropdownCell(
7171
std::string label,
72-
CheckboxDropdownDatabase&& database,
72+
Database&& database,
7373
LockMode lock_while_running,
7474
FlagEnum default_value, FlagEnum current_value
7575
) = delete;
@@ -105,7 +105,7 @@ class CheckboxDropdownCell : public CheckboxDropdownBase{
105105

106106

107107
private:
108-
const CheckboxDropdownDatabase& m_database;
108+
const Database& m_database;
109109
const FlagEnum m_default;
110110

111111
mutable SpinLock m_lock;

Common/Cpp/Options/CheckboxDropdownOption.tpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace PokemonAutomation{
2020
template <typename FlagEnum>
2121
CheckboxDropdownCell<FlagEnum>::CheckboxDropdownCell(
2222
std::string label,
23-
const CheckboxDropdownDatabase& database,
23+
const Database& database,
2424
LockMode lock_while_running,
2525
FlagEnum default_value
2626
)
@@ -32,7 +32,7 @@ CheckboxDropdownCell<FlagEnum>::CheckboxDropdownCell(
3232
template <typename FlagEnum>
3333
CheckboxDropdownCell<FlagEnum>::CheckboxDropdownCell(
3434
std::string label,
35-
const CheckboxDropdownDatabase& database,
35+
const Database& database,
3636
LockMode lock_while_running,
3737
FlagEnum default_value, FlagEnum current_value
3838
)

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){

0 commit comments

Comments
 (0)