mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
add role list to user menu
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "member.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
|
||||
void from_json(const nlohmann::json &j, GuildMember &m) {
|
||||
JS_O("user", m.User);
|
||||
@@ -10,6 +11,21 @@ void from_json(const nlohmann::json &j, GuildMember &m) {
|
||||
JS_D("mute", m.IsMuted);
|
||||
}
|
||||
|
||||
std::vector<RoleData> GuildMember::GetSortedRoles() const {
|
||||
std::vector<RoleData> roles;
|
||||
for (const auto role_id : Roles) {
|
||||
const auto role = Abaddon::Get().GetDiscordClient().GetRole(role_id);
|
||||
if (!role.has_value()) continue;
|
||||
roles.push_back(std::move(*role));
|
||||
}
|
||||
|
||||
std::sort(roles.begin(), roles.end(), [](const RoleData &a, const RoleData &b) {
|
||||
return a.Position > b.Position;
|
||||
});
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
GuildMember GuildMember::from_update_json(const nlohmann::json &j) {
|
||||
GuildMember ret;
|
||||
JS_D("roles", ret.Roles);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "snowflake.hpp"
|
||||
#include "json.hpp"
|
||||
#include "user.hpp"
|
||||
#include "role.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -14,6 +15,8 @@ struct GuildMember {
|
||||
bool IsDeafened;
|
||||
bool IsMuted;
|
||||
|
||||
std::vector<RoleData> GetSortedRoles() const;
|
||||
|
||||
friend void from_json(const nlohmann::json &j, GuildMember &m);
|
||||
static GuildMember from_update_json(const nlohmann::json &j);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user