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 role_data related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file RoleEntities.hpp
30#pragma once
31
35
36namespace discord_core_api {
37
38 /**
39 * \addtogroup foundation_entities
40 * @{
41 */
42
43 /// @brief For addin a role_data to a guild_member.
45 snowflake guildId{};///< The id of the guild within which to assign the role_data.
46 jsonifier::string reason{};///< Reason for adding the guild_member_data's role_data.
47 snowflake userId{};///< The id of the user_data to whom to assign the role_data.
48 snowflake roleId{};///< The id of the role_data to be assigned.
49 };
50
51 /// @brief For removing a role_data from a guild_member.
53 jsonifier::string reason{};///< Reason for removing the guild_member_data's role_data.
54 snowflake guildId{};///< The id of the guild within which to remove the role_data.
55 snowflake userId{};///< The id of the user_data from whom to remove the role_data.
56 snowflake roleId{};///< The id of the role_data to be removed.
57 };
58
59 /// @brief For getting a chosen guild's roles.
61 snowflake guildId{};///< Guild id for which guild to get the roles from.
62 };
63
64 /// @brief For creating a new role_data within a chosen guild.
66 permissions_parse permissions{};///< The base permissions to give the role_data.
67 jsonifier::string hexColorValue{};///< Hex color-value between 0 and ffffff.
68 jsonifier::string unicodeEmoji{};///< The role's unicode emoji as a standard emoji.
69 jsonifier::string reason{};///< Reason for creating the role_data.
70 snowflake guildId{};///< Which guild to make the role_data in.
71 jsonifier::string icon{};///< Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
72 bool mentionable{};///< Is it mentionable by others in the guild.
73 uint32_t position{};///< The position amongst the other roles.
74 jsonifier::string name{};///< The name of the role_data.
75 bool hoist{};///< Is this role_data hoisted above the rest of them?
76 };
77
78 /// @brief For updating the positions of the roles.
80 uint32_t rolePosition{};///< The new role_data position.
81 snowflake roleId{};///< The role_data to update.
82 };
83
84 /// @brief For updating the role_data positions.
86 template<typename value_type> friend struct jsonifier::core;
87 friend class roles;
88
89 uint32_t newPosition{};///< The new position of the role_data.
90 jsonifier::string reason{};///< Reason for modifying the role_data positions.
91 snowflake guildId{};///< The guild within which to move the role_data.
92 snowflake roleId{};///< The id of the role_data to move.
93
94 protected:
95 jsonifier::vector<role_position_data> rolePositions;
96 };
97
98 /// @brief For updating a role_data's options within a chosen guild.
100 permissions_parse permissions{ "0" };///< Base guild permissions for the role_data.
101 jsonifier::string hexColorValue{};///< A hex-color value between 0x00 and 0xFFFFFF.
102 jsonifier::string unicodeEmoji{};///< The role's unicode emoji as a standard emoji.
103 jsonifier::string reason{};///<< reason for modifying the role_data.
104 snowflake guildId{};///< The id of the guild within which to update the role_data.
105 jsonifier::string icon{};///< Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
106 bool mentionable{};///< Is it mentionable?
107 snowflake roleId{};///< The id of the role_data to update.
108 jsonifier::string name{};///< What the name of the role_data is going to be.
109 bool hoist{};///< Is this role_data hoisted above the others?
110 };
111
112 /// @brief For removing a role_data from a chosen guild.
114 jsonifier::string reason{};///< Reason for removing this role_data.
115 snowflake guildId{};///< The id of the guild from which to remove the role_data.
116 snowflake roleId{};///< The id of the role_data to remove.
117 };
118
119 /// @brief For getting a chosen guild_member_data's roles.
121 guild_member_data guildMember{};///< Which guild member to collect the roles from.
122 snowflake guildId{};///< Which guild to collect their roles from.
123 };
124
125 /// @brief For getting a role_data from the library's cache, or the discord server.
127 snowflake guildId{};///< Which guild to collect the role_data from.
128 snowflake roleId{};///< Which role_data to collect.
129 };
130
131 /**@}*/
132
133 /**
134 * \addtogroup main_endpoints
135 * @{
136 */
137 /// @brief An interface class for the role_data related discord endpoints.
138 class DiscordCoreAPI_Dll roles {
139 public:
141 friend class discord_core_client;
142 friend class role_data;
143 friend class guild_data;
144 friend class guild;
145
146 static void initialize(discord_core_internal::https_client*, config_manager* configManagerNew);
147
148 /// @brief Adds a role_data to a chosen guild member.
149 /// @param dataPackage an add_guild_member_role_data structure.
150 /// @return a co_routine containing void.
151 static co_routine<void> addGuildMemberRoleAsync(const add_guild_member_role_data dataPackage);
152
153 /// @brief Removes a given role from a chosen guild_member_data.
154 /// @param dataPackage a remove_guild_member_role_data structure.
155 /// @return a co_routine containing void.
156 static co_routine<void> removeGuildMemberRoleAsync(const remove_guild_member_role_data dataPackage);
157
158 /// @brief Collects the roles that a guild has.
159 /// @param dataPackage a get_guild_roles_data structure.
160 /// @return a co_routine containing a jsonifier::vector<role_data>.
161 static co_routine<jsonifier::vector<role_data>> getGuildRolesAsync(const get_guild_roles_data dataPackage);
162
163 /// @brief Creates a new role_data within the given guild.
164 /// @param dataPackage a create_guild_role_data structure.
165 /// @return a co_routine containing a role_data.
166 static co_routine<role_data> createGuildRoleAsync(const create_guild_role_data dataPackage);
167
168 /// @brief Updates a role_data's positions.
169 /// @param dataPackage a modify_guild_role_positions_data structure.
170 /// @return a co_routine containing a jsonifier::vector<role_data>.
171 static co_routine<jsonifier::vector<role_data>> modifyGuildRolePositionsAsync(modify_guild_role_positions_data dataPackage);
172
173 /// @brief Updates a given role's properties.
174 /// @param dataPackage a modify_guild_role_data structure.
175 /// @return a co_routine containing a role_data.
176 static co_routine<role_data> modifyGuildRoleAsync(const modify_guild_role_data dataPackage);
177
178 /// @brief Removes a given role from a guild.
179 /// @param dataPackage a remove_guild_role_data structure.
180 /// @return a co_routine containing void.
181 static co_routine<void> removeGuildRoleAsync(const remove_guild_role_data dataPackage);
182
183 /// @brief Collects the roles that a guild_member has.
184 /// @param dataPackage a get_guild_member_roles_data structure.
185 /// @return a co_routine containing a jsonifier::vector<role_data>.
186 static co_routine<jsonifier::vector<role_data>> getGuildMemberRolesAsync(const get_guild_member_roles_data dataPackage);
187
188 /// @brief Collects a role_data from the discord servers.
189 /// @param dataPackage a get_role_data structure.
190 /// @return a co_routine containing a role_data.
191 static co_routine<role_data> getRoleAsync(const get_role_data dataPackage);
192
193 /// @brief Collects a given role from the library's cache.
194 /// @param dataPackage a get_role_data structure.
195 /// @return a co_routine containing a role_data.
196 static role_cache_data getCachedRole(const get_role_data dataPackage);
197
198 template<typename role_type> inline static void insertRole(role_type&& role) {
199 if (doWeCacheRolesBool) {
200 if (role.id == 0) {
201 throw dca_exception{ "Sorry, but there was no id set for that role." };
202 }
203 cache.emplace(static_cast<role_cache_data>(std::forward<role_type>(role)));
204 if (cache.count() % 1000 == 0) {
205 std::cout << "current role count: " << cache.count() << std::endl;
206 }
207 }
208 }
209
210 static void removeRole(const role_cache_data& roleId);
211
212 static bool doWeCacheRoles();
213
214 protected:
215 static discord_core_internal::https_client* httpsClient;
217 static bool doWeCacheRolesBool;
218 };
219 /**@}*/
220
221}
A co_routine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:83
discord_core_client - the main class for this library.
A websocket client, for communication via a tcp-connection.
A discord guild. used to connect to/disconnect from voice.
Data structure representing a single guild_member_data.
A template class representing an object cache.
Definition: ObjectCache.hpp:40
Data structure representing a single role_data.
An interface class for the role_data related discord endpoints.
A class representing a snowflake identifier with various operations.
Definition: Base.hpp:680
The main namespace for the forward-facing interfaces.
For addin a role_data to a guild_member.
snowflake guildId
The id of the guild within which to assign the role_data.
snowflake userId
The id of the user_data to whom to assign the role_data.
jsonifier::string reason
Reason for adding the guild_member_data's role_data.
snowflake roleId
The id of the role_data to be assigned.
For creating a new role_data within a chosen guild.
bool hoist
Is this role_data hoisted above the rest of them?
uint32_t position
The position amongst the other roles.
jsonifier::string hexColorValue
Hex color-value between 0 and ffffff.
snowflake guildId
Which guild to make the role_data in.
jsonifier::string reason
Reason for creating the role_data.
jsonifier::string name
The name of the role_data.
jsonifier::string unicodeEmoji
The role's unicode emoji as a standard emoji.
permissions_parse permissions
The base permissions to give the role_data.
bool mentionable
Is it mentionable by others in the guild.
jsonifier::string icon
Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
An exception class derived from std::runtime_error for dca-related exceptions.
Definition: Base.hpp:820
For getting a chosen guild_member_data's roles.
snowflake guildId
Which guild to collect their roles from.
guild_member_data guildMember
Which guild member to collect the roles from.
For getting a chosen guild's roles.
snowflake guildId
Guild id for which guild to get the roles from.
For getting a role_data from the library's cache, or the discord server.
snowflake roleId
Which role_data to collect.
snowflake guildId
Which guild to collect the role_data from.
For updating a role_data's options within a chosen guild.
jsonifier::string icon
Image data the role's icon image (if the guild has the ROLE_ICONS feature) null.
permissions_parse permissions
Base guild permissions for the role_data.
jsonifier::string name
What the name of the role_data is going to be.
jsonifier::string unicodeEmoji
The role's unicode emoji as a standard emoji.
bool hoist
Is this role_data hoisted above the others?
jsonifier::string reason
< reason for modifying the role_data.
snowflake roleId
The id of the role_data to update.
jsonifier::string hexColorValue
A hex-color value between 0x00 and 0xFFFFFF.
snowflake guildId
The id of the guild within which to update the role_data.
For updating the role_data positions.
jsonifier::string reason
Reason for modifying the role_data positions.
snowflake guildId
The guild within which to move the role_data.
snowflake roleId
The id of the role_data to move.
uint32_t newPosition
The new position of the role_data.
For removing a role_data from a guild_member.
jsonifier::string reason
Reason for removing the guild_member_data's role_data.
snowflake roleId
The id of the role_data to be removed.
snowflake userId
The id of the user_data from whom to remove the role_data.
snowflake guildId
The id of the guild within which to remove the role_data.
For removing a role_data from a chosen guild.
snowflake guildId
The id of the guild from which to remove the role_data.
jsonifier::string reason
Reason for removing this role_data.
snowflake roleId
The id of the role_data to remove.
For updating the positions of the roles.
uint32_t rolePosition
The new role_data position.
snowflake roleId
The role_data to update.