mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
fix calculating hoisted color role
also slight optimization + make Snowflake::Invalid a real Snowflake
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
constexpr static uint64_t DiscordEpochSeconds = 1420070400;
|
||||
|
||||
const Snowflake Snowflake::Invalid = -1ULL;
|
||||
|
||||
Snowflake::Snowflake()
|
||||
: m_num(Invalid) {}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ struct Snowflake {
|
||||
return m_num;
|
||||
}
|
||||
|
||||
const static uint64_t Invalid = -1ULL; // makes sense to me
|
||||
const static Snowflake Invalid; // makes sense to me
|
||||
const static uint64_t SecondsInterval = 4194304000ULL; // the "difference" between two snowflakes one second apart
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Snowflake &s);
|
||||
|
||||
Reference in New Issue
Block a user