aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
role.hpp
1 //
2 // role.hpp
3 // ********
4 //
5 // Copyright (c) 2019 Sharon W (sharon at aegis dot gg)
6 //
7 // Distributed under the MIT License. (See accompanying file LICENSE)
8 //
9 
10 #pragma once
11 
12 #include "aegis/config.hpp"
13 #include "aegis/snowflake.hpp"
14 #include "aegis/permission.hpp"
15 #include <nlohmann/json.hpp>
16 
17 namespace aegis
18 {
19 
20 namespace gateway
21 {
22 
23 namespace objects
24 {
25 
26 struct role;
27 
29 void from_json(const nlohmann::json& j, role& m);
30 void to_json(nlohmann::json& j, const role& m);
32 
34 struct role
35 {
36  role(const std::string & _json, aegis::core * bot) noexcept
37  {
38  from_json(nlohmann::json::parse(_json), *this);
39  }
40 
41  role(const nlohmann::json & _json, aegis::core * bot) noexcept
42  {
43  from_json(_json, *this);
44  }
45 
46  role(aegis::core * bot) noexcept {}
47 
48  role() noexcept {}
49 
50  uint32_t color = 0;
51  snowflake id;
52  snowflake role_id; //<deprecated use role::id instead
53  std::string name;
54  aegis::permission _permission;
55  uint16_t position = 0;
56  bool hoist = false;
57  bool managed = false;
58  bool mentionable = false;
59 };
60 
62 inline void from_json(const nlohmann::json& j, role& m)
63 {
64  if (j.count("color") && !j["color"].is_null())
65  m.color = j["color"];
66  if (j.count("id") && !j["id"].is_null())
67  m.id = m.role_id = j["id"];
68  if (j.count("name") && !j["name"].is_null())
69  m.name = j["name"].get<std::string>();
70  if (j.count("permissions") && !j["permissions"].is_null())
71  m._permission = j["permissions"];
72  if (j.count("position") && !j["position"].is_null())
73  m.position = j["position"];
74  if (j.count("hoist") && !j["hoist"].is_null())
75  m.hoist = j["hoist"];
76  if (j.count("mentionable") && !j["mentionable"].is_null())
77  m.mentionable = j["mentionable"];
78 }
79 
80 inline void to_json(nlohmann::json& j, const role& m)
81 {
82  j["color"] = m.color;
83  j["id"] = std::to_string(m.id);
84  j["name"] = m.name;
85  j["permissions"] = m._permission;
86  j["position"] = m.position;
87  j["hoist"] = m.hoist;
88  j["mentionable"] = m.mentionable;
89 }
91 
92 }
93 
94 }
95 
96 }
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
Utility class for permission checks.
Definition: permission.hpp:57
Primary class for managing a bot interface.
Definition: core.hpp:157
Stores info pertaining to guild roles.
Definition: role.hpp:34