aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
permission.hpp
1 //
2 // permission.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/fwd.hpp"
14 #include <stdint.h>
15 
16 namespace aegis
17 {
18 
19 /*
20 I made this, but then i didn't need it. It is here now, if it becomes needed in the future
21 enum permissions : int64_t {
22  CREATE_INSTANT_INVITE = 0x00000001,
23  KICK_MEMBERS = 0x00000002,
24  BAN_MEMBERS = 0x00000004,
25  ADMINISTRATOR = 0x00000008,
26  MANAGE_CHANNELS = 0x00000010,
27  MANAGE_GUILD = 0x00000020,
28  ADD_REACTIONS = 0x00000040,
29  VIEW_AUDIT_LOG = 0x00000080,
30  VIEW_CHANNEL = 0x00000400,
31  SEND_MESSAGES = 0x00000800,
32  SEND_TTS_MESSAGES = 0x00001000,
33  MANAGE_MESSAGES = 0x00002000,
34  EMBED_LINKS = 0x00004000,
35  ATTACH_FILES = 0x00008000,
36  READ_MESSAGE_HISTORY = 0x00010000,
37  MENTION_EVERYONE = 0x00020000,
38  USE_EXTERNAL_EMOJIS = 0x00040000,
39  VIEW_GUILD_INSIGHTS = 0x00080000,
40  CONNECT = 0x00100000,
41  SPEAK = 0x00200000,
42  MUTE_MEMBERS = 0x00400000,
43  DEAFEN_MEMBERS = 0x00800000,
44  MOVE_MEMBERS = 0x01000000,
45  USE_VAD = 0x02000000,
46  PRIORITY_SPEAKER = 0x00000100,
47  STREAM = 0x00000200,
48  CHANGE_NICKNAME = 0x04000000,
49  MANAGE_NICKNAMES = 0x08000000,
50  MANAGE_ROLES = 0x10000000,
51  MANAGE_WEBHOOKS = 0x20000000,
52  MANAGE_EMOJIS = 0x40000000
53 };
54 */
55 
58 {
59 public:
60  permission() = default;
61  permission(int64_t allow) : _allow_permissions(allow) {}
62  //permission(const permission&) = delete;
63 
64  operator int64_t() const noexcept
65  {
66  return _allow_permissions;
67  }
68 
69  int64_t get_allow_perms() const noexcept { return _allow_permissions; }
70  bool can_invite() const noexcept { return (_allow_permissions & 0x1) > 0; }
71  bool can_kick() const noexcept { return (_allow_permissions & 0x2) > 0; }
72  bool can_ban() const noexcept { return (_allow_permissions & 0x4) > 0; }
73  bool is_admin() const noexcept { return (_allow_permissions & 0x8) > 0; }
74  bool can_manage_channels() const noexcept { return (_allow_permissions & 0x10) > 0; }
75  bool can_manage_guild() const noexcept { return (_allow_permissions & 0x20) > 0; }
76  bool can_add_reactions() const noexcept { return (_allow_permissions & 0x40) > 0; }
77  bool can_view_audit_logs() const noexcept { return (_allow_permissions & 0x80) > 0; }
78  bool can_read_messages() const noexcept { return (_allow_permissions & 0x400) > 0; }
79  bool can_send_messages() const noexcept { return (_allow_permissions & 0x800) > 0; }
80  bool can_tts() const noexcept { return (_allow_permissions & 0x1000) > 0; }
81  bool can_manage_messages() const noexcept { return (_allow_permissions & 0x2000) > 0; }
82  bool can_embed() const noexcept { return (_allow_permissions & 0x4000) > 0; }
83  bool can_attach_files() const noexcept { return (_allow_permissions & 0x8000) > 0; }
84  bool can_read_history() const noexcept { return (_allow_permissions & 0x10000) > 0; }
85  bool can_mention_everyone() const noexcept { return (_allow_permissions & 0x20000) > 0; }
86  bool can_external_emoiji() const noexcept { return (_allow_permissions & 0x40000) > 0; }
87  bool can_change_name() const noexcept { return (_allow_permissions & 0x4000000) > 0; }
88  bool can_manage_names() const noexcept { return (_allow_permissions & 0x8000000) > 0; }
89  bool can_manage_roles() const noexcept { return (_allow_permissions & 0x10000000) > 0; }
90  bool can_manage_webhooks() const noexcept { return (_allow_permissions & 0x20000000) > 0; }
91  bool can_manage_emojis() const noexcept { return (_allow_permissions & 0x40000000) > 0; }
92 
93  bool can_voice_connect() const noexcept { return (_allow_permissions & 0x100000) > 0; }
94  bool can_voice_mute() const noexcept { return (_allow_permissions & 0x400000) > 0; }
95  bool can_voice_speak() const noexcept { return (_allow_permissions & 0x200000) > 0; }
96  bool can_voice_deafen() const noexcept { return (_allow_permissions & 0x800000) > 0; }
97  bool can_voice_move() const noexcept { return (_allow_permissions & 0x1000000) > 0; }
98  bool can_voice_activity() const noexcept { return (_allow_permissions & 0x2000000) > 0; }
99  bool has_priority_speaker() const noexcept { return (_allow_permissions & 0x100) > 0; }
100 
101  void set_invite() noexcept { _allow_permissions = (_allow_permissions & 0x1); }
102  void set_kick() noexcept { _allow_permissions = (_allow_permissions & 0x2); }
103  void set_ban() noexcept { _allow_permissions = (_allow_permissions & 0x4); }
104  void set_admin() noexcept { _allow_permissions = (_allow_permissions & 0x8); }
105  void set_manage_channels() noexcept { _allow_permissions = (_allow_permissions & 0x10); }
106  void set_manage_guild() noexcept { _allow_permissions = (_allow_permissions & 0x20); }
107  void set_add_reactions() noexcept { _allow_permissions = (_allow_permissions & 0x40); }
108  void set_view_audit_logs() noexcept { _allow_permissions = (_allow_permissions & 0x80); }
109  void set_read_messages() noexcept { _allow_permissions = (_allow_permissions & 0x400); }
110  void set_send_messages() noexcept { _allow_permissions = (_allow_permissions & 0x800); }
111  void set_tts() noexcept { _allow_permissions = (_allow_permissions & 0x1000); }
112  void set_manage_messages() noexcept { _allow_permissions = (_allow_permissions & 0x2000); }
113  void set_embed() noexcept { _allow_permissions = (_allow_permissions & 0x4000); }
114  void set_attach_files() noexcept { _allow_permissions = (_allow_permissions & 0x8000); }
115  void set_read_history() noexcept { _allow_permissions = (_allow_permissions & 0x10000); }
116  void set_mention_everyone() noexcept { _allow_permissions = (_allow_permissions & 0x20000); }
117  void set_external_emoiji() noexcept { _allow_permissions = (_allow_permissions & 0x40000); }
118  void set_change_name() noexcept { _allow_permissions = (_allow_permissions & 0x4000000); }
119  void set_manage_names() noexcept { _allow_permissions = (_allow_permissions & 0x8000000); }
120  void set_manage_roles() noexcept { _allow_permissions = (_allow_permissions & 0x10000000); }
121  void set_manage_webhooks() noexcept { _allow_permissions = (_allow_permissions & 0x20000000); }
122  void set_manage_emojis() noexcept { _allow_permissions = (_allow_permissions & 0x40000000); }
123 
124  void set_voice_connect() noexcept { _allow_permissions = (_allow_permissions & 0x100000); }
125  void set_voice_mute() noexcept { _allow_permissions = (_allow_permissions & 0x400000); }
126  void set_voice_speak() noexcept { _allow_permissions = (_allow_permissions & 0x200000); }
127  void set_voice_deafen() noexcept { _allow_permissions = (_allow_permissions & 0x800000); }
128  void set_voice_move() noexcept { _allow_permissions = (_allow_permissions & 0x1000000); }
129  void set_voice_activity() noexcept { _allow_permissions = (_allow_permissions & 0x2000000); }
130 
131 private:
132  int64_t _allow_permissions = 0;
133 };
134 
136 AEGIS_DECL void from_json(const nlohmann::json& j, permission& s);
137 
138 AEGIS_DECL void to_json(nlohmann::json& j, const permission& s);
140 
141 }
142 
143 #if defined(AEGIS_HEADER_ONLY)
144 #include "aegis/impl/permission.cpp"
145 #endif
Utility class for permission checks.
Definition: permission.hpp:57