aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
guild.hpp
1 //
2 // guild.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/guild_member.hpp"
15 #include "aegis/gateway/objects/channel.hpp"
16 #include "aegis/gateway/objects/role.hpp"
17 #include "aegis/gateway/objects/voice_state.hpp"
18 #include "aegis/gateway/objects/presence.hpp"
19 #include "aegis/gateway/objects/emoji.hpp"
20 #include <nlohmann/json.hpp>
21 #include <string>
22 #include <vector>
23 
24 namespace aegis
25 {
26 
27 namespace gateway
28 {
29 
30 namespace objects
31 {
32 
34 void from_json(const nlohmann::json& j, guild& m);
35 void to_json(nlohmann::json& j, const guild& m);
37 
40 struct guild
41 {
42  guild(const std::string & _json, aegis::core * bot) noexcept
43  {
44  from_json(nlohmann::json::parse(_json), *this);
45  }
46 
47  guild(const nlohmann::json & _json, aegis::core * bot) noexcept
48  {
49  from_json(_json, *this);
50  }
51 
52  guild(aegis::core * bot) noexcept {}
53 
54  guild() noexcept {}
55 
56  //TODO:
59  std::string name;
60  std::string icon;
61  std::string splash;
63  std::string region;
65  int32_t afk_timeout = 0;
66  bool embed_enabled = false;
68  int8_t verification_level = 0;
71  std::vector<objects::role> roles;
72  std::vector<objects::emoji> emojis;
73  std::vector<std::string> features;
74  int8_t mfa_level = 0;
75  snowflake application_id;//? /**<\todo Needs documentation */
76  bool widget_enabled = false;
78  //createonly
79  std::string joined_at;
80  bool large = false;
81  bool unavailable = false;
82  int32_t member_count = 0;
83  std::vector<objects::voice_state> voice_states;
84  std::vector<objects::guild_member> members;
85  std::vector<objects::channel> channels;
86  std::vector<objects::presence> presences;
87 };
88 
89 
91 inline void from_json(const nlohmann::json& j, guild& m)
92 {
93  if (j.count("id") && !j["id"].is_null())
94  m.id = m.guild_id = j["id"];
95  if (j.count("name") && !j["name"].is_null())
96  m.name = j["name"].get<std::string>();
97  if (j.count("icon") && !j["icon"].is_null())
98  m.icon = j["icon"].get<std::string>();
99  if (j.count("splash") && !j["splash"].is_null())
100  m.splash = j["splash"].get<std::string>();
101  if (j.count("owner_id") && !j["owner_id"].is_null())
102  m.owner_id = j["owner_id"];
103  if (j.count("region") && !j["region"].is_null())
104  m.region = j["region"].get<std::string>();
105  if (j.count("afk_channel_id") && !j["afk_channel_id"].is_null())
106  m.afk_channel_id = j["afk_channel_id"];
107  if (j.count("afk_timeout") && !j["afk_timeout"].is_null())
108  m.afk_timeout = j["afk_timeout"];
109  if (j.count("embed_enabled") && !j["embed_enabled"].is_null())
110  m.embed_enabled = j["embed_enabled"];
111  if (j.count("embed_channel_id") && !j["embed_channel_id"].is_null())
112  m.embed_channel_id = j["embed_channel_id"];
113  if (j.count("verification_level") && !j["verification_level"].is_null())
114  m.verification_level = j["verification_level"];
115  if (j.count("default_message_notifications") && !j["default_message_notifications"].is_null())
116  m.default_message_notifications = j["default_message_notifications"];
117  if (j.count("mfa_level") && !j["mfa_level"].is_null())
118  m.mfa_level = j["mfa_level"];
119  if (j.count("joined_at") && !j["joined_at"].is_null())
120  m.joined_at = j["joined_at"].get<std::string>();
121  if (j.count("large") && !j["large"].is_null())
122  m.large = j["large"];
123  if (j.count("unavailable") && !j["unavailable"].is_null())
124  m.unavailable = j["unavailable"];
125  else
126  m.unavailable = false;
127  if (j.count("member_count") && !j["member_count"].is_null())
128  m.member_count = j["member_count"];
129 
130  if (j.count("roles"))
131  for (const auto & _role : j["roles"])
132  m.roles.push_back(_role);
133 
134  if (j.count("members"))
135  for (const auto & _member : j["members"])
136  m.members.push_back(_member);
137 
138  if (j.count("channels"))
139  for (const auto & _channel : j["channels"])
140  m.channels.push_back(_channel);
141 
142  if (j.count("presences"))
143  for (const auto & _presence : j["presences"])
144  m.presences.push_back(_presence);
145 
146  if (j.count("emojis"))
147  for (const auto & _emoji : j["emojis"])
148  m.emojis.push_back(_emoji);
149 
150  if (j.count("voice_states"))
151  for (const auto & _voicestate : j["voice_states"])
152  m.voice_states.push_back(_voicestate);
153 
154  if (j.count("features"))
155  for (const auto & _feature : j["features"])
156  m.features.push_back(_feature);
157 }
158 
159 inline void to_json(nlohmann::json& j, const guild& m)
160 {
161 
162 }
164 
165 }
166 
167 }
168 
169 }
Definition: guild.hpp:40
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
int8_t verification_level
Definition: guild.hpp:68
bool unavailable
Definition: guild.hpp:81
std::string name
Definition: guild.hpp:59
bool widget_enabled
Definition: guild.hpp:76
Class for performing actions pertaining to a specified guild.
Definition: guild.hpp:159
int8_t mfa_level
Definition: guild.hpp:74
Primary class for managing a bot interface.
Definition: core.hpp:157
snowflake id
Definition: guild.hpp:57
std::vector< objects::presence > presences
Definition: guild.hpp:86
int32_t member_count
Definition: guild.hpp:82
std::vector< objects::role > roles
Definition: guild.hpp:71
std::vector< std::string > features
Definition: guild.hpp:73
std::vector< objects::voice_state > voice_states
Definition: guild.hpp:83
snowflake afk_channel_id
Definition: guild.hpp:64
int8_t default_message_notifications
Definition: guild.hpp:69
snowflake embed_channel_id
Definition: guild.hpp:67
std::vector< objects::emoji > emojis
Definition: guild.hpp:72
std::vector< objects::channel > channels
Definition: guild.hpp:85
std::string region
Definition: guild.hpp:63
snowflake widget_channel_id
Definition: guild.hpp:77
int8_t explicit_content_filter
Definition: guild.hpp:70
snowflake guild_id
Definition: guild.hpp:58
std::string splash
Definition: guild.hpp:61
bool large
Definition: guild.hpp:80
snowflake owner_id
Definition: guild.hpp:62
int32_t afk_timeout
Definition: guild.hpp:65
std::vector< objects::guild_member > members
Definition: guild.hpp:84
std::string icon
Definition: guild.hpp:60
bool embed_enabled
Definition: guild.hpp:66
std::string joined_at
Definition: guild.hpp:79