aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
embed.hpp
1 //
2 // embed.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/field.hpp"
15 #include "aegis/gateway/objects/footer.hpp"
16 #include "aegis/gateway/objects/image.hpp"
17 #include "aegis/gateway/objects/thumbnail.hpp"
18 #include "aegis/gateway/objects/video.hpp"
19 #include "aegis/gateway/objects/provider.hpp"
20 #include <nlohmann/json.hpp>
21 
22 namespace aegis
23 {
24 
25 namespace gateway
26 {
27 
28 namespace objects
29 {
30 
33 class embed
34 {
35 public:
37 
42  embed& fields(const std::vector<objects::field>& flds) noexcept
43  {
44  _fields = flds;
45  return *this;
46  }
47 
49 
52  embed& title(const std::string& str) noexcept
53  {
54  _title = str;
55  return *this;
56  }
57 
59 
62  embed& footer(const objects::footer ftr) noexcept
63  {
64  _footer = ftr;
65  return *this;
66  }
67 
69 
72  embed& description(const std::string& str) noexcept
73  {
74  _description = str;
75  return *this;
76  }
77 
79 
82  embed& url(const std::string& str) noexcept
83  {
84  _url = str;
85  return *this;
86  }
87 
89 
92  embed& timestamp(const std::string& str) noexcept
93  {
94  _timestamp = str;
95  return *this;
96  }
97 
99 
102  embed& color(const int32_t clr) noexcept
103  {
104  _color = clr;
105  return *this;
106  }
107 
109 
112  embed& thumbnail(const objects::thumbnail& tn) noexcept
113  {
114  _thumbnail = tn;
115  return *this;
116  }
117 
119 
122  embed& image(const objects::image& img) noexcept
123  {
124  _image = img;
125  return *this;
126  }
127 
129  std::vector<objects::field>& fields() noexcept
130  {
131  return _fields;
132  }
133 
135  std::string& title() noexcept
136  {
137  return _title;
138  }
139 
142  {
143  return _footer;
144  }
145 
147  std::string& description() noexcept
148  {
149  return _description;
150  }
151 
153  std::string& url() noexcept
154  {
155  return _url;
156  }
157 
159  std::string& timestamp() noexcept
160  {
161  return _timestamp;
162  }
163 
165  int32_t& color() noexcept
166  {
167  return _color;
168  }
169 
172  {
173  return _thumbnail;
174  }
175 
177  objects::image& image() noexcept
178  {
179  return _image;
180  }
181 
182 private:
183  // Combined Limit: 6000
184  std::string _title; // Limit: 256
185  std::string _type;
186  std::string _description; // Limit: 2048
187  std::string _url;
188  std::string _timestamp;
189  int32_t _color = 0;
190  objects::footer _footer; // Limit: 2048
191  objects::image _image;
192  objects::thumbnail _thumbnail;
193  objects::video _video;
194  objects::provider _provider;
195  std::vector<objects::field> _fields; // Limit: 25 name:256 value:1024
196  friend void from_json(const nlohmann::json& j, embed& m);
197  friend void to_json(nlohmann::json& j, const embed& m);
198 };
199 
201 inline void from_json(const nlohmann::json& j, embed& m)
202 {
203  if (j.count("title") && !j["title"].is_null())
204  m._title = j["title"].get<std::string>();
205  if (j.count("type"))
206  m._type = j["type"].get<std::string>();
207  if (j.count("description") && !j["description"].is_null())
208  m._description = j["description"].get<std::string>();
209  if (j.count("url") && !j["url"].is_null())
210  m._url = j["url"].get<std::string>();
211  if (j.count("timestamp") && !j["timestamp"].is_null())
212  m._timestamp = j["timestamp"].get<std::string>();
213  if (j.count("color") && !j["color"].is_null())
214  m._color = j["color"];
215  if (j.count("footer") && !j["footer"].is_null())
216  m._footer = j["footer"];
217  if (j.count("image") && !j["image"].is_null())
218  m._image = j["image"];
219  if (j.count("thumbnail") && !j["thumbnail"].is_null())
220  m._thumbnail = j["thumbnail"];
221  if (j.count("video") && !j["video"].is_null())
222  m._video = j["video"];
223  if (j.count("provider") && !j["provider"].is_null())
224  m._provider = j["provider"];
225  if (j.count("fields") && !j["fields"].is_null())
226  for (const auto& _field : j["fields"])
227  m._fields.push_back(_field);
228 }
229 
230 inline void to_json(nlohmann::json & j, const embed & m)
231 {
232  j["title"] = m._title;
233  //j["type"] = m._type;
234  j["description"] = m._description;
235  if (m._url.size())
236  j["url"] = m._url;
237  j["timestamp"] = m._timestamp;
238  j["color"] = m._color;
239  if (m._footer.text.size())
240  j["footer"] = m._footer;
241  if (m._image.url.size())
242  j["image"] = m._image;
243  if (m._thumbnail.url.size())
244  j["thumbnail"] = m._thumbnail;
245  //j["video"] = m._video;
246  //j["provider"] = m._provider;
247  for (const auto& _field : m._fields)
248  j["fields"].push_back(_field);
249 }
251 
252 }
253 
254 }
255 
256 }
objects::thumbnail & thumbnail() noexcept
Get the thumbnail.
Definition: embed.hpp:171
embed & description(const std::string &str) noexcept
Sets the description of the embed.
Definition: embed.hpp:72
std::vector< objects::field > & fields() noexcept
Get the fields.
Definition: embed.hpp:129
Definition: embed.hpp:33
embed & title(const std::string &str) noexcept
Sets the title of the embed.
Definition: embed.hpp:52
std::string & url() noexcept
Get the url.
Definition: embed.hpp:153
embed & footer(const objects::footer ftr) noexcept
Sets the footer of the embed.
Definition: embed.hpp:62
Definition: image.hpp:26
int32_t & color() noexcept
Get the color.
Definition: embed.hpp:165
embed & image(const objects::image &img) noexcept
Sets the image of the embed.
Definition: embed.hpp:122
objects::footer & footer() noexcept
Get the footer.
Definition: embed.hpp:141
std::string & description() noexcept
Get the description.
Definition: embed.hpp:147
embed & fields(const std::vector< objects::field > &flds) noexcept
Adds a new embed field.
Definition: embed.hpp:42
std::string & timestamp() noexcept
Get the timestamp.
Definition: embed.hpp:159
embed & timestamp(const std::string &str) noexcept
Sets the timestamp of the embed.
Definition: embed.hpp:92
objects::image & image() noexcept
Get the image.
Definition: embed.hpp:177
embed & color(const int32_t clr) noexcept
Sets the color of the embed.
Definition: embed.hpp:102
Definition: footer.hpp:26
Definition: thumbnail.hpp:26
Definition: video.hpp:28
embed & url(const std::string &str) noexcept
Sets the url of the embed.
Definition: embed.hpp:82
std::string & title() noexcept
Get the title.
Definition: embed.hpp:135
embed & thumbnail(const objects::thumbnail &tn) noexcept
Sets the thumbnail of the embed.
Definition: embed.hpp:112
Definition: provider.hpp:26