aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
attachment.hpp
1 //
2 // attachment.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 <nlohmann/json.hpp>
15 #include <string>
16 
17 namespace aegis
18 {
19 
20 namespace gateway
21 {
22 
23 namespace objects
24 {
25 
28 struct attachment
29 {
31  std::string filename;
32  int32_t size = 0;
33  std::string url;
34  std::string proxy_url;
35  int32_t height = 0;
36  int32_t width = 0;
37 };
38 
40 inline void from_json(const nlohmann::json& j, attachment& m)
41 {
42  if (j.count("id"))
43  m.id = j["id"];
44  if (j.count("filename"))
45  m.filename = j["filename"].get<std::string>();
46  if (j.count("size"))
47  m.size = j["size"];
48  if (j.count("url"))
49  m.url = j["url"].get<std::string>();
50  if (j.count("proxy_url"))
51  m.proxy_url = j["proxy_url"].get<std::string>();
52  if (j.count("height") && !j["height"].is_null())
53  m.height = j["height"];
54  if (j.count("width") && !j["width"].is_null())
55  m.width = j["width"];
56 }
57 
58 inline void to_json(nlohmann::json& j, const attachment& m)
59 {
60  j["id"] = m.id;
61  j["filename"] = m.filename;
62  j["size"] = m.size;
63  j["url"] = m.url;
64  j["proxy_url"] = m.proxy_url;
65  j["height"] = m.height;
66  j["width"] = m.width;
67 }
69 
70 }
71 
72 }
73 
74 }
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
std::string filename
Definition: attachment.hpp:31
int32_t size
Definition: attachment.hpp:32
int32_t height
Definition: attachment.hpp:35
std::string proxy_url
Definition: attachment.hpp:34
Definition: attachment.hpp:28
int32_t width
Definition: attachment.hpp:36
snowflake id
Definition: attachment.hpp:30
std::string url
Definition: attachment.hpp:33