From 658b5873f5f2bc44f1361fb81f81b04a17cea59a Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Mon, 2 Oct 2023 13:55:17 +0000 Subject: [PATCH] fix: make things compile properly due to making nickname, roles and flags private --- include/dpp/guild.h | 4 +++- src/dpp/guild.cpp | 8 ++++---- src/dpp/role.cpp | 9 +++++---- src/unittest/coro.cpp | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/dpp/guild.h b/include/dpp/guild.h index d5a92582f2..7c0e12c229 100644 --- a/include/dpp/guild.h +++ b/include/dpp/guild.h @@ -196,6 +196,8 @@ class DPP_EXPORT guild_member { std::vector roles; /** A set of flags built from the bitmask defined by dpp::guild_member_flags */ uint16_t flags; + + friend void from_json(const nlohmann::json& j, guild_member& gm); public: /** Guild id */ snowflake guild_id; @@ -337,7 +339,7 @@ class DPP_EXPORT guild_member { * * @return std::vector roles */ - std::vector get_roles(); + std::vector get_roles() const; /** * @brief Find the dpp::user object for this member. This is an alias for dpp::find_user diff --git a/src/dpp/guild.cpp b/src/dpp/guild.cpp index 80cf237392..6d77c5cd9d 100644 --- a/src/dpp/guild.cpp +++ b/src/dpp/guild.cpp @@ -134,7 +134,7 @@ std::string guild_member::get_nickname() { return nickname; } -std::vector guild_member::get_roles() { +std::vector guild_member::get_roles() const { return roles; } @@ -752,7 +752,7 @@ permission guild::base_permissions(const guild_member &member) const { permission permissions = everyone->permissions; - for (auto& rid : member.roles) { + for (auto& rid : member.get_roles()) { role* r = dpp::find_role(rid); if (r) { permissions |= r->permissions; @@ -799,7 +799,7 @@ permission guild::permission_overwrites(const uint64_t base_permissions, const u uint64_t allow = 0; uint64_t deny = 0; - for (auto& rid : gm.roles) { + for (auto& rid : gm.get_roles()) { /* Skip \@everyone role to not break the hierarchy. It's calculated above */ if (rid == this->id) { @@ -855,7 +855,7 @@ permission guild::permission_overwrites(const guild_member &member, const channe uint64_t allow = 0; uint64_t deny = 0; - for (auto& rid : member.roles) { + for (auto& rid : member.get_roles()) { /* Skip \@everyone role to not break the hierarchy. It's calculated above */ if (rid == this->id) { diff --git a/src/dpp/role.cpp b/src/dpp/role.cpp index ca4ae672a5..8c14160d89 100644 --- a/src/dpp/role.cpp +++ b/src/dpp/role.cpp @@ -413,8 +413,9 @@ members_container role::get_members() const { } for (auto & m : g->members) { /* Iterate all members and use std::find on their role list to see who has this role */ - auto i = std::find(m.second.roles.begin(), m.second.roles.end(), this->id); - if (i != m.second.roles.end()) { + auto r = m.second.get_roles(); + auto i = std::find(r.begin(), r.end(), this->id); + if (i != r.end()) { gm[m.second.user_id] = m.second; } } @@ -425,8 +426,8 @@ members_container role::get_members() const { std::string role::get_icon_url(uint16_t size, const image_type format) const { if (!this->icon.to_string().empty() && this->id) { return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp }, - "role-icons/" + std::to_string(this->id) + "/" + this->icon.to_string(), - format, size); + "role-icons/" + std::to_string(this->id) + "/" + this->icon.to_string(), + format, size); } else { return std::string(); } diff --git a/src/unittest/coro.cpp b/src/unittest/coro.cpp index 677e19d32f..1e6e819cf0 100644 --- a/src/unittest/coro.cpp +++ b/src/unittest/coro.cpp @@ -460,7 +460,7 @@ void event_handler_test(dpp::cluster *bot) { if (!pair.first.has_value()) { co_return {}; } - const std::string& member_nick = pair.second.has_value() ? pair.second->nickname : ""; + const std::string& member_nick = pair.second.has_value() ? pair.second->get_nickname() : ""; const std::string& user_nick = pair.first->username; result = co_await bot->co_message_edit(msg.set_content("coro " + (member_nick.empty() ? user_nick : member_nick) + " " + std::to_string(i))); co_return result.is_error() ? dpp::snowflake{} : std::get(result.value).id;