aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
activity.hpp
1 //
2 // activity.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/timestamp.hpp"
15 #include "aegis/gateway/objects/party.hpp"
16 #include "aegis/gateway/objects/asset.hpp"
17 #include "aegis/gateway/objects/secret.hpp"
18 #include <nlohmann/json.hpp>
19 
20 namespace aegis
21 {
22 
23 namespace gateway
24 {
25 
26 namespace objects
27 {
28 
31 struct activity
32 {
33  enum activity_type
34  {
35  Game = 0,
36  Streaming = 1,
37  Listening = 2,
38  Watching = 3
39  };
40  enum activity_flags
41  {
42  Null = 0,
43  Instance = 1,
44  Join = 1 << 1,
45  Spectate = 1 << 2,
46  JoinRequest = 1 << 3,
47  Sync = 1 << 4,
48  Play = 1 << 5
49  };
50  std::string name;
51  activity_type type = activity_type::Game;
52  std::string url;
53  objects::timestamp timestamps;
54  snowflake application_id;
55  std::string details;
56  std::string state;
57  objects::party party_data;
58  objects::asset assets;
59  objects::secret secrets;
60  bool instance;
61  activity_flags flags;
62 };
63 
65 inline void from_json(const nlohmann::json& j, activity& m)
66 {
67  if (j.count("name") && !j["name"].is_null())
68  m.name = j["name"].get<std::string>();
69  if (j.count("type") && !j["type"].is_null())
70  m.type = static_cast<objects::activity::activity_type>(j["type"].get<int32_t>());
71  if (j.count("url") && !j["url"].is_null())
72  m.url = j["url"].get<std::string>();
73  if (j.count("timestamps") && !j["timestamps"].is_null())
74  m.timestamps = j["timestamps"];
75  if (j.count("party") && !j["party"].is_null())
76  m.party_data = j["party"];
77  if (j.count("assets") && !j["assets"].is_null())
78  m.assets = j["assets"];
79  if (j.count("secrets") && !j["secrets"].is_null())
80  m.secrets = j["secrets"];
81  if (j.count("application_id") && !j["application_id"].is_null())
82  m.application_id = j["application_id"];
83  if (j.count("details") && !j["details"].is_null())
84  m.details = j["details"].get<std::string>();
85  if (j.count("state") && !j["state"].is_null())
86  m.state = j["state"].get<std::string>();
87  if (j.count("instance") && !j["instance"].is_null())
88  m.instance = j["instance"];
89  if (j.count("flags") && !j["flags"].is_null())
90  m.flags = j["flags"];
91 }
92 
93 inline void to_json(nlohmann::json& j, const activity& m)
94 {
95  j["name"] = m.name;
96  j["type"] = static_cast<int32_t>(m.type);
97  if (!m.name.empty())
98  {
99  j["flags"] = static_cast<int32_t>(m.flags);
100  if (!m.url.empty())
101  if (m.type == activity::Streaming || m.type == activity::Watching)
102  j["url"] = m.url;
103  if (m.type == activity::Game)
104  {
105  if (!m.details.empty())
106  j["details"] = m.details;
107  if (!m.state.empty())
108  j["state"] = m.state;
109  j["party"] = m.party_data;
110  j["assets"] = m.assets;
111  j["secrets"] = m.secrets;
112  j["application_id"] = m.application_id;
113  j["instance"] = m.instance;
114  }
115  }
116 }
118 
119 }
120 
121 }
122 
123 }
Definition: secret.hpp:26
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
Definition: timestamp.hpp:26
Definition: activity.hpp:31
Definition: asset.hpp:26
Definition: party.hpp:26