aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
member.hpp
1 //
2 // member.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/gateway/objects/role.hpp"
15 #include <nlohmann/json.hpp>
16 
17 namespace aegis
18 {
19 
20 namespace gateway
21 {
22 
23 namespace objects
24 {
25 
26 struct member;
27 
29 void from_json(const nlohmann::json& j, member& m);
30 void to_json(nlohmann::json& j, const member& m);
32 
35 struct member
36 {
37  member(const std::string & _json, aegis::core * bot) noexcept
38  {
39  from_json(nlohmann::json::parse(_json), *this);
40  }
41 
42  member(const nlohmann::json & _json, aegis::core * bot) noexcept
43  {
44  from_json(_json, *this);
45  }
46 
47  member(aegis::core * bot) noexcept {}
48 
49  member() noexcept {}
50 
51  std::vector<objects::role> roles;
52  std::string nick;
53  std::string joined_at;
54  bool mute = false;
55  bool deaf = false;
56 };
57 
59 inline void from_json(const nlohmann::json& j, member& m)
60 {
61  if (j.count("roles") && !j["roles"].is_null())
62  for (const auto & _role : j["roles"])
63  m.roles.push_back(_role);
64  if (j.count("nick") && !j["nick"].is_null())
65  m.nick = j["nick"].get<std::string>();
66  if (j.count("joined_at") && !j["joined_at"].is_null())
67  m.joined_at = j["joined_at"].get<std::string>();
68  if (j.count("mute") && !j["mute"].is_null())
69  m.mute = j["mute"];
70  if (j.count("deaf") && !j["deaf"].is_null())
71  m.deaf = j["deaf"];
72 }
73 
74 inline void to_json(nlohmann::json& j, const member& m)
75 {
76  for (const auto & i : m.roles)
77  j["roles"].push_back(i);
78  j["nick"] = m.nick;
79  j["joined_at"] = m.joined_at;
80  j["mute"] = m.mute;
81  j["deaf"] = m.deaf;
82 }
84 
85 }
86 
87 }
88 
89 }
Primary class for managing a bot interface.
Definition: core.hpp:157
Definition: member.hpp:35
std::string nick
Definition: member.hpp:52