summaryrefslogtreecommitdiff
path: root/discord/discord.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-03-07 01:34:08 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-03-07 01:34:08 -0500
commitf1746bbeea0f88b5d1745b829b9ccf343df6ae72 (patch)
treeb29efef7abc49155f8d3801c3ff4232f43a72596 /discord/discord.cpp
parent9186a4f3f5723989dc07ee5fe2d59aa88f0de552 (diff)
downloadabaddon-portaudio-f1746bbeea0f88b5d1745b829b9ccf343df6ae72.tar.gz
abaddon-portaudio-f1746bbeea0f88b5d1745b829b9ccf343df6ae72.zip
edit guild-level permissions for roles
- also reduce db access a little in GetMemberHighestRole
Diffstat (limited to 'discord/discord.cpp')
-rw-r--r--discord/discord.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 7cd87bc..387d2b3 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -227,15 +227,19 @@ Snowflake DiscordClient::GetMemberHoistedRole(Snowflake guild_id, Snowflake user
return roles[0].ID;
}
-Snowflake DiscordClient::GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const {
+std::optional<RoleData> DiscordClient::GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const {
const auto data = GetMember(user_id, guild_id);
- if (!data.has_value()) return Snowflake::Invalid;
+ if (!data.has_value()) return std::nullopt;
+
+ if (data->Roles.size() == 0) return std::nullopt;
+ if (data->Roles.size() == 1) return GetRole(data->Roles[0]);
- if (data->Roles.size() == 0) return Snowflake::Invalid;
- if (data->Roles.size() == 1) return data->Roles[0];
+ std::vector<RoleData> roles;
+ for (const auto id : data->Roles)
+ roles.push_back(*GetRole(id));
- return *std::max_element(data->Roles.begin(), data->Roles.end(), [this](const auto &a, const auto &b) -> bool {
- return GetRole(a)->Position < GetRole(b)->Position;
+ return *std::max_element(roles.begin(), roles.end(), [this](const auto &a, const auto &b) -> bool {
+ return a.Position < b.Position;
});
}
@@ -334,10 +338,8 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
bool DiscordClient::CanManageMember(Snowflake guild_id, Snowflake actor, Snowflake target) const {
const auto guild = GetGuild(guild_id);
if (guild.has_value() && guild->OwnerID == target) return false;
- const auto actor_highest_id = GetMemberHighestRole(guild_id, actor);
- const auto target_highest_id = GetMemberHighestRole(guild_id, target);
- const auto actor_highest = GetRole(actor_highest_id);
- const auto target_highest = GetRole(target_highest_id);
+ const auto actor_highest = GetMemberHighestRole(guild_id, actor);
+ const auto target_highest = GetMemberHighestRole(guild_id, target);
if (!actor_highest.has_value()) return false;
if (!target_highest.has_value()) return true;
return actor_highest->Position > target_highest->Position;
@@ -537,6 +539,14 @@ void DiscordClient::RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_
});
}
+void DiscordClient::ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, sigc::slot<void(bool success)> callback) {
+ ModifyGuildRoleObject obj;
+ obj.Permissions = permissions;
+ m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) {
+ callback(CheckCode(response));
+ });
+}
+
std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) {
return m_store.GetBans(guild_id);
}