aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
channel.hpp
1 //
2 // channel.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/user.hpp"
15 #include "permission_overwrite.hpp"
16 #include <nlohmann/json.hpp>
17 
18 namespace aegis
19 {
20 
21 namespace gateway
22 {
23 
24 namespace objects
25 {
26 
28 void from_json(const nlohmann::json& j, channel& m);
29 void to_json(nlohmann::json& j, const channel& m);
31 
33 struct channel
34 {
35  channel(const std::string & _json, aegis::core * bot) noexcept
36  {
37  from_json(nlohmann::json::parse(_json), *this);
38  }
39 
40  channel(const nlohmann::json & _json, aegis::core * bot) noexcept
41  {
42  from_json(_json, *this);
43  }
44 
45  channel(aegis::core * bot) noexcept {}
46 
47  channel() noexcept {}
48 
51  {
52  Text = 0,
54  Voice = 2,
56  Category = 4
57  };
58 
63  int position = 0;
64  std::vector<objects::permission_overwrite> permission_overwrites;
65  std::string name;
66  std::string topic;
67  bool nsfw = false;
69  int bitrate = 0;
70  int userlimit = 0;
71  std::vector<objects::user> recipients;
72  std::string icon;
76 };
77 
79 inline void from_json(const nlohmann::json& j, channel& m)
80 {
81  m.id = m.channel_id = j["id"];
82  m.type = j["type"];
83  if (j.count("guild_id") && !j["guild_id"].is_null())
84  m.guild_id = j["guild_id"];
85  if (j.count("position") && !j["position"].is_null())
86  m.position = j["position"];
87  if (j.count("permission_overwrites") && !j["permission_overwrites"].is_null())
88  for (const auto & i : j["permission_overwrites"])
89  m.permission_overwrites.push_back(i);
90  if (j.count("name") && !j["name"].is_null())
91  m.name = j["name"].get<std::string>();
92  if (j.count("topic") && !j["topic"].is_null())
93  m.topic = j["topic"].get<std::string>();
94  if (j.count("nsfw") && !j["nsfw"].is_null())
95  m.nsfw = j["nsfw"];
96  if (j.count("last_message_id") && !j["last_message_id"].is_null())
97  m.last_message_id = j["last_message_id"];
98  if (j.count("bitrate") && !j["bitrate"].is_null())
99  m.bitrate = j["bitrate"];
100  if (j.count("userlimit") && !j["userlimit"].is_null())
101  m.userlimit = j["userlimit"];
102  if (j.count("icon") && !j["icon"].is_null())
103  m.icon = j["icon"].get<std::string>();
104  if (j.count("owner_id") && !j["owner_id"].is_null())
105  m.owner_id = j["owner_id"];
106  if (j.count("application_id") && !j["application_id"].is_null())
107  m.application_id = j["application_id"];
108  if (j.count("parent_id") && !j["parent_id"].is_null())
109  m.parent_id = j["parent_id"];
110  if (j.count("recipients") && !j["recipients"].is_null())
111  for (const auto & i : j["recipients"])
112  m.recipients.push_back(i);
113 }
114 
115 inline void to_json(nlohmann::json& j, const channel& m)
116 {
117  if (m.channel_id)
118  j["id"] = std::to_string(m.id);
119  j["type"] = m.type;
120  if (m.guild_id)
121  j["guild_id"] = m.guild_id;
122  if (m.position)
123  j["position"] = m.position;
124  j["name"] = m.name;
125  if (!m.topic.empty())
126  j["topic"] = m.topic;
127  if (m.nsfw)
128  j["nsfw"] = m.nsfw;
129  if (m.last_message_id)
130  j["last_message_id"] = m.last_message_id;
131  if (m.bitrate)
132  j["bitrate"] = m.bitrate;
133  if (m.userlimit)
134  j["userlimit"] = m.userlimit;
135  if (!m.icon.empty())
136  j["icon"] = m.icon;
137  if (m.bitrate)
138  j["owner_id"] = m.owner_id;
139  if (m.application_id)
140  j["application_id"] = m.application_id;
141  if (m.parent_id)
142  j["parent_id"] = m.parent_id;
143 
144  if (!m.permission_overwrites.empty())
145  for (auto i : m.permission_overwrites)
146  j["permission_overwrites"].push_back(i);
147 
148  if (!m.recipients.empty())
149  for (auto i : m.recipients)
150  j["recipients"].push_back(i);
151 }
153 
154 }
155 
156 }
157 
158 }
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
snowflake application_id
Definition: channel.hpp:74
int bitrate
Definition: channel.hpp:69
std::vector< objects::permission_overwrite > permission_overwrites
Definition: channel.hpp:64
Definition: channel.hpp:52
Primary class for managing a bot interface.
Definition: core.hpp:157
Class for performing actions pertaining to a specified channel.
Definition: channel.hpp:170
snowflake owner_id
Definition: channel.hpp:73
int position
Definition: channel.hpp:63
Definition: channel.hpp:54
std::string icon
Definition: channel.hpp:72
snowflake channel_id
Definition: channel.hpp:60
std::string name
Definition: channel.hpp:65
std::string topic
Definition: channel.hpp:66
bool nsfw
Definition: channel.hpp:67
bool nsfw() const noexcept
Get if this channel is set to NSFW.
Definition: channel.hpp:600
snowflake last_message_id
Definition: channel.hpp:68
std::vector< objects::user > recipients
Definition: channel.hpp:71
channel_type
Enumeration of the channel types.
Definition: channel.hpp:50
Represents a guild or DM channel within Discord.
Definition: channel.hpp:33
channel_type type
Definition: channel.hpp:61
int userlimit
Definition: channel.hpp:70
snowflake guild_id
Definition: channel.hpp:62
snowflake parent_id
Definition: channel.hpp:75
snowflake id
Definition: channel.hpp:59