DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
RoleEntities.hpp
Go to the documentation of this file.
1/*
2 MIT License
3
4 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
5
6 Copyright 2022, 2023 Chris M. (RealTimeChris)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26/// RoleEntities.hpp - Header for the RoleData related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file RoleEntities.hpp
30
31#pragma once
32
36
37namespace DiscordCoreAPI {
38
39 /**
40 * \addtogroup foundation_entities
41 * @{
42 */
43
44 /// @brief For addin a RoleData to a GuildMember.
46 Snowflake guildId{};///< The id of the Guild within which to assign the RoleData.
47 std::string reason{};///< Reason for adding the GuildMemberData's RoleData.
48 Snowflake userId{};///< The id of the UserData to whom to assign the RoleData.
49 Snowflake roleId{};///< The id of the RoleData to be assigned.
50 };
51
52 /// @brief For removing a RoleData from a GuildMember.
54 std::string reason{};///< Reason for removing the GuildMemberData's RoleData.
55 Snowflake guildId{};///< The id of the Guild within which to remove the RoleData.
56 Snowflake userId{};///< The id of the UserData from whom to remove the RoleData.
57 Snowflake roleId{};///< The id of the RoleData to be removed.
58 };
59
60 /// @brief For getting a chosen Guild's Roles.
62 Snowflake guildId{};///< Guild id for which Guild to get the roles from.
63 };
64
65 /// @brief For creating a new RoleData within a chosen Guild.
67 PermissionsParse permissions{};///< The base permissions to give the RoleData.
68 std::string hexColorValue{};///< Hex color-value between 0 and ffffff.
69 std::string unicodeEmoji{};///< The role's unicode emoji as a standard emoji.
70 std::string reason{};///< Reason for creating the RoleData.
71 Snowflake guildId{};///< Which Guild to make the RoleData in.
72 std::string icon{};///< Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
73 bool mentionable{};///< Is it mentionable by others in the Guild.
74 uint32_t position{};///< The position amongst the other roles.
75 std::string name{};///< The name of the RoleData.
76 bool hoist{};///< Is this RoleData hoisted above the rest of them?
77 };
78
79 /// @brief For updating the positions of the roles.
81 uint32_t rolePosition{};///< The new RoleData position.
82 Snowflake roleId{};///< The RoleData to update.
83 };
84
85 /// @brief For updating the RoleData positions.
87 template<typename ValueType> friend struct jsonifier::core;
88 friend class Roles;
89
90 uint32_t newPosition{};///< The new position of the RoleData.
91 std::string reason{};///< Reason for modifying the RoleData positions.
92 Snowflake guildId{};///< The Guild within which to move the RoleData.
93 Snowflake roleId{};///< The id of the RoleData to move.
94
95 protected:
96 jsonifier::vector<RolePositionData> rolePositions;
97 };
98
99 /// @brief For updating a RoleData's options within a chosen Guild.
101 PermissionsParse permissions{ "0" };///< Base Guild permissions for the RoleData.
102 std::string hexColorValue{};///< A hex-color value between 0x00 and 0xFFFFFF.
103 std::string unicodeEmoji{};///< The role's unicode emoji as a standard emoji.
104 std::string reason{};///<< Reason for modifying the RoleData.
105 Snowflake guildId{};///< The id of the Guild within which to update the RoleData.
106 std::string icon{};///< Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
107 bool mentionable{};///< Is it mentionable?
108 Snowflake roleId{};///< The id of the RoleData to update.
109 std::string name{};///< What the name of the RoleData is going to be.
110 bool hoist{};///< Is this RoleData hoisted above the others?
111 };
112
113 /// @brief For removing a RoleData from a chosen Guild.
115 std::string reason{};///< Reason for removing this RoleData.
116 Snowflake guildId{};///< The id of the Guild from which to remove the RoleData.
117 Snowflake roleId{};///< The id of the RoleData to remove.
118 };
119
120 /// @brief For getting a chosen GuildMemberData's Roles.
122 GuildMemberData guildMember{};///< Which Guild member to collect the roles from.
123 Snowflake guildId{};///< Which Guild to collect their roles from.
124 };
125
126 /// @brief For getting a RoleData from the library's cache, or the Discord server.
127 struct GetRoleData {
128 Snowflake guildId{};///< Which Guild to collect the RoleData from.
129 Snowflake roleId{};///< Which RoleData to collect.
130 };
131
132 /**@}*/
133
134 /**
135 * \addtogroup main_endpoints
136 * @{
137 */
138 /// @brief An interface class for the RoleData related Discord endpoints.
139 class DiscordCoreAPI_Dll Roles {
140 public:
141 friend class DiscordCoreInternal::WebSocketClient;
142 friend class DiscordCoreClient;
143 friend class RoleData;
144 friend class GuildData;
145 friend class Guild;
146
147 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManagerNew);
148
149 /// @brief Adds a RoleData to a chosen Guild member.
150 /// @param dataPackage An AddGuildMemberRoleData structure.
151 /// @return A CoRoutine containing void.
152 static CoRoutine<void> addGuildMemberRoleAsync(AddGuildMemberRoleData dataPackage);
153
154 /// @brief Removes a given Role from a chosen GuildMemberData.
155 /// @param dataPackage A RemoveGuildMemberRoleData structure.
156 /// @return A CoRoutine containing void.
157 static CoRoutine<void> removeGuildMemberRoleAsync(RemoveGuildMemberRoleData dataPackage);
158
159 /// @brief Collects the Roles that a Guild has.
160 /// @param dataPackage A GetGuildRolesData structure.
161 /// @return A CoRoutine containing a jsonifier::vector<RoleData>.
162 static CoRoutine<jsonifier::vector<RoleData>> getGuildRolesAsync(GetGuildRolesData dataPackage);
163
164 /// @brief Creates a new RoleData within the given Guild.
165 /// @param dataPackage A CreateGuildRoleData structure.
166 /// @return A CoRoutine containing a RoleData.
167 static CoRoutine<RoleData> createGuildRoleAsync(CreateGuildRoleData dataPackage);
168
169 /// @brief Updates a RoleData's positions.
170 /// @param dataPackage A ModifyGuildRolePositionsData structure.
171 /// @return A CoRoutine containing a jsonifier::vector<RoleData>.
172 static CoRoutine<jsonifier::vector<RoleData>> modifyGuildRolePositionsAsync(ModifyGuildRolePositionsData dataPackage);
173
174 /// @brief Updates a given Role's properties.
175 /// @param dataPackage A ModifyGuildRoleData structure.
176 /// @return A CoRoutine containing a RoleData.
177 static CoRoutine<RoleData> modifyGuildRoleAsync(ModifyGuildRoleData dataPackage);
178
179 /// @brief Removes a given Role from a Guild.
180 /// @param dataPackage A RemoveGuildRoleData structure.
181 /// @return A CoRoutine containing void.
182 static CoRoutine<void> removeGuildRoleAsync(RemoveGuildRoleData dataPackage);
183
184 /// @brief Collects the Roles that a GuildMember has.
185 /// @param dataPackage A GetGuildMemberRolesData structure.
186 /// @return A CoRoutine containing a jsonifier::vector<RoleData>.
187 static CoRoutine<jsonifier::vector<RoleData>> getGuildMemberRolesAsync(GetGuildMemberRolesData dataPackage);
188
189 /// @brief Collects a RoleData from the Discord servers.
190 /// @param dataPackage A GetRoleData structure.
191 /// @return A CoRoutine containing a RoleData.
192 static CoRoutine<RoleData> getRoleAsync(GetRoleData dataPackage);
193
194 /// @brief Collects a given Role from the library's cache.
195 /// @param dataPackage A GetRoleData structure.
196 /// @return A CoRoutine containing a RoleData.
197 static RoleCacheData getCachedRole(GetRoleData dataPackage);
198
199 template<typename RoleType> static inline void insertRole(RoleType&& role) {
200 if (doWeCacheRolesBool) {
201 if (role.id == 0) {
202 throw DCAException{ "Sorry, but there was no id set for that role." };
203 }
204 cache.emplace(static_cast<RoleCacheData>(std::forward<RoleType>(role)));
205 if (cache.count() % 1000 == 0) {
206 std::cout << "CURRENT ROLE COUNT: " << cache.count() << std::endl;
207 }
208 }
209 }
210
211 static void removeRole(const RoleCacheData& roleId);
212
213 static bool doWeCacheRoles();
214
215 protected:
216 static DiscordCoreInternal::HttpsClient* httpsClient;
217 static ObjectCache<RoleCacheData> cache;
218 static bool doWeCacheRolesBool;
219 };
220 /**@}*/
221
222}
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:88
DiscordCoreClient - The main class for this library.
Data structure representing a single RoleData.
Data structure representing a single GuildMemberData.
A discord Guild. Used to connect to/disconnect from voice.
For addin a RoleData to a GuildMember.
std::string reason
Reason for adding the GuildMemberData's RoleData.
Snowflake userId
The id of the UserData to whom to assign the RoleData.
Snowflake roleId
The id of the RoleData to be assigned.
Snowflake guildId
The id of the Guild within which to assign the RoleData.
For removing a RoleData from a GuildMember.
Snowflake userId
The id of the UserData from whom to remove the RoleData.
std::string reason
Reason for removing the GuildMemberData's RoleData.
Snowflake guildId
The id of the Guild within which to remove the RoleData.
Snowflake roleId
The id of the RoleData to be removed.
For getting a chosen Guild's Roles.
Snowflake guildId
Guild id for which Guild to get the roles from.
For creating a new RoleData within a chosen Guild.
std::string name
The name of the RoleData.
Snowflake guildId
Which Guild to make the RoleData in.
bool hoist
Is this RoleData hoisted above the rest of them?
bool mentionable
Is it mentionable by others in the Guild.
uint32_t position
The position amongst the other roles.
std::string unicodeEmoji
The role's unicode emoji as a standard emoji.
std::string icon
Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
std::string reason
Reason for creating the RoleData.
std::string hexColorValue
Hex color-value between 0 and ffffff.
PermissionsParse permissions
The base permissions to give the RoleData.
For updating the positions of the roles.
Snowflake roleId
The RoleData to update.
uint32_t rolePosition
The new RoleData position.
For updating the RoleData positions.
Snowflake guildId
The Guild within which to move the RoleData.
std::string reason
Reason for modifying the RoleData positions.
uint32_t newPosition
The new position of the RoleData.
Snowflake roleId
The id of the RoleData to move.
For updating a RoleData's options within a chosen Guild.
std::string name
What the name of the RoleData is going to be.
std::string unicodeEmoji
The role's unicode emoji as a standard emoji.
std::string icon
Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
Snowflake roleId
The id of the RoleData to update.
PermissionsParse permissions
Base Guild permissions for the RoleData.
std::string reason
< Reason for modifying the RoleData.
Snowflake guildId
The id of the Guild within which to update the RoleData.
bool hoist
Is this RoleData hoisted above the others?
bool mentionable
Is it mentionable?
std::string hexColorValue
A hex-color value between 0x00 and 0xFFFFFF.
For removing a RoleData from a chosen Guild.
Snowflake roleId
The id of the RoleData to remove.
std::string reason
Reason for removing this RoleData.
Snowflake guildId
The id of the Guild from which to remove the RoleData.
For getting a chosen GuildMemberData's Roles.
GuildMemberData guildMember
Which Guild member to collect the roles from.
Snowflake guildId
Which Guild to collect their roles from.
For getting a RoleData from the library's cache, or the Discord server.
Snowflake guildId
Which Guild to collect the RoleData from.
Snowflake roleId
Which RoleData to collect.
An interface class for the RoleData related Discord endpoints.
A class representing a Snowflake identifier with various operations.
Definition: Base.hpp:771
An exception class derived from std::runtime_error for DCA-related exceptions.
Definition: Base.hpp:879
A template class representing an object cache.
Definition: ObjectCache.hpp:41