aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
permission_overwrite.hpp
1 //
2 // permission_overwrite.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 
16 namespace aegis
17 {
18 
19 namespace gateway
20 {
21 
22 namespace objects
23 {
24 
27 enum overwrite_type
28 {
29  User,
30  Role
31 };
32 
36 {
38  //either "role" or "member"
39  objects::overwrite_type type = User;
40  int64_t allow = 0;
41  int64_t deny = 0;
42 };
43 
45 inline void from_json(const nlohmann::json& j, permission_overwrite& m)
46 {
47  m.id = j["id"];
48  if (j.count("type"))
49  m.type = (j["type"] == "role") ? (objects::overwrite_type::Role) : (objects::overwrite_type::User);
50  m.allow = j["allow"];
51  m.deny = j["deny"];
52 }
53 
54 inline void to_json(nlohmann::json& j, const permission_overwrite& m)
55 {
56  j["id"] = m.id;
57  j["type"] = (m.type == objects::overwrite_type::Role)?"role":"member";
58  j["allow"] = m.allow;
59  j["deny"] = m.deny;
60 }
62 
63 }
64 
65 }
66 
67 }
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
int64_t allow
Definition: permission_overwrite.hpp:40
snowflake id
Definition: permission_overwrite.hpp:37
objects::overwrite_type type
Definition: permission_overwrite.hpp:39
int64_t deny
Definition: permission_overwrite.hpp:41
Definition: permission_overwrite.hpp:35