summaryrefslogtreecommitdiff
path: root/discord/discord.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-07-21 01:29:17 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-07-21 01:29:17 -0400
commita5e5954ae72c59feeaa54c328d89a46f048dbf47 (patch)
treea7d016963ef42051cee57beaad405b1ed3f3014c /discord/discord.cpp
parentccf7c414be476d9be601a3dfe0e0030dedc0a91c (diff)
downloadabaddon-portaudio-a5e5954ae72c59feeaa54c328d89a46f048dbf47.tar.gz
abaddon-portaudio-a5e5954ae72c59feeaa54c328d89a46f048dbf47.zip
fix calculating hoisted color role
also slight optimization + make Snowflake::Invalid a real Snowflake
Diffstat (limited to 'discord/discord.cpp')
-rw-r--r--discord/discord.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index fab2c49..8dc1ef8 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -205,22 +205,17 @@ Snowflake DiscordClient::GetMemberHoistedRole(Snowflake guild_id, Snowflake user
const auto data = GetMember(user_id, guild_id);
if (!data.has_value()) return Snowflake::Invalid;
- std::vector<RoleData> roles;
+ std::optional<RoleData> top_role;
for (const auto &id : data->Roles) {
const auto role = GetRole(id);
if (role.has_value()) {
- if (role->IsHoisted || (with_color && role->Color != 0))
- roles.push_back(*role);
+ if ((with_color && role->Color != 0x000000) || (!with_color && role->IsHoisted))
+ if (!top_role.has_value() || top_role->Position < role->Position)
+ top_role = role;
}
}
- if (roles.size() == 0) return Snowflake::Invalid;
-
- std::sort(roles.begin(), roles.end(), [this](const RoleData &a, const RoleData &b) -> bool {
- return a.Position > b.Position;
- });
-
- return roles[0].ID;
+ return top_role.has_value() ? top_role->ID : Snowflake::Invalid;
}
std::optional<RoleData> DiscordClient::GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const {