39 static constexpr auto parseValue = createObject(
"guild_id", &value_type::guildId,
"id", &value_type::roleId,
"positions", &value_type::rolePositions,
"reason",
40 &value_type::reason,
"position", &value_type::newPosition);
45 static constexpr auto parseValue = createObject(
"color", &value_type::hexColorValue,
"hoist", &value_type::hoist,
"id", &value_type::roleId,
"mentionable",
46 &value_type::mentionable,
"name", &value_type::name,
"permissions", &value_type::permissions,
"reason", &value_type::reason,
"unicode_emoji", &value_type::unicodeEmoji,
47 "guild_id", &value_type::guildId,
"icon", &value_type::icon);
52 static constexpr auto parseValue = createObject(
"color", &value_type::hexColorValue,
"hoist", &value_type::hoist,
"id", &value_type::guildId,
"mentionable",
53 &value_type::mentionable,
"name", &value_type::name,
"permissions", &value_type::permissions,
"position", &value_type::position,
"reason", &value_type::reason,
54 "unicode_emoji", &value_type::unicodeEmoji,
"icon", &value_type::icon);
59 static constexpr auto parseValue = createObject(
"position", &value_type::rolePosition,
"id", &value_type::roleId);
65 role_cache_data& role_cache_data::operator=(
const role_data& other) {
67 setFlagValue<role_flags>(role_flags::mentionable, other.mentionable);
68 setFlagValue<role_flags>(role_flags::managed, other.managed);
69 setFlagValue<role_flags>(role_flags::hoist, other.hoist);
70 if (other.unicodeEmoji !=
"") {
73 if (other.permissions.operator std::string_view() !=
"") {
76 if (other.position != 0) {
79 if (other.color != 0) {
82 if (other.name !=
"") {
91 role_cache_data::role_cache_data(
const role_data& other) {
95 role_cache_data& role_cache_data::operator=(role_data&& other)
noexcept {
97 setFlagValue<role_flags>(role_flags::mentionable, other.mentionable);
98 setFlagValue<role_flags>(role_flags::managed, other.managed);
99 setFlagValue<role_flags>(role_flags::hoist, other.hoist);
100 if (other.unicodeEmoji !=
"") {
101 unicodeEmoji = std::move(other.unicodeEmoji);
103 if (other.permissions.operator std::string_view() !=
"") {
104 permissionsVal = std::move(other.permissions);
106 if (other.name !=
"") {
107 name = std::move(other.name);
109 if (other.position != 0) {
110 position = other.position;
112 if (other.color != 0) {
123 returnData.mentionable = getFlagValue<role_flags>(role_flags::mentionable);
124 returnData.managed = getFlagValue<role_flags>(role_flags::managed);
125 returnData.hoist = getFlagValue<role_flags>(role_flags::hoist);
126 returnData.permissions = permissionsVal.operator jsonifier::string();
127 returnData.unicodeEmoji = unicodeEmoji;
128 returnData.position = position;
129 returnData.flags = flags;
130 returnData.color = color;
131 returnData.name = name;
136 role_cache_data::role_cache_data(role_data&& other)
noexcept {
137 *
this = std::move(other);
140 role_data::role_data(snowflake newId) {
144 void roles::initialize(discord_core_internal::https_client* client, config_manager* configManagerNew) {
145 roles::doWeCacheRolesBool = configManagerNew->doWeCacheRoles();
146 roles::httpsClient = client;
150 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Put_Guild_Member_Role };
151 co_await newThreadAwaitable<void>();
152 workload.workloadClass = discord_core_internal::https_workload_class::Put;
153 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/members/" + dataPackage.
userId +
"/roles/" + dataPackage.
roleId;
154 workload.callStack =
"roles::addGuildMemberRoleAsync()";
155 if (dataPackage.
reason !=
"") {
156 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
158 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload));
163 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Guild_Member_Role };
164 co_await newThreadAwaitable<void>();
165 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
166 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/members/" + dataPackage.
userId +
"/roles/" + dataPackage.
roleId;
167 workload.callStack =
"roles::removeGuildMemberRoleAsync()";
168 if (dataPackage.
reason !=
"") {
169 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
171 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload));
176 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Roles };
177 co_await newThreadAwaitable<jsonifier::vector<role_data>>();
178 if (dataPackage.
guildId == 0) {
179 throw dca_exception{
"roles::getGuildRolesAsync() error: sorry, but you forgot to set the guildId!" };
181 workload.workloadClass = discord_core_internal::https_workload_class::Get;
182 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/roles";
183 workload.callStack =
"roles::getGuildRolesAsync()";
184 jsonifier::vector<role_data> returnData{};
185 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
186 co_return returnData;
190 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Guild_Role };
191 co_await newThreadAwaitable<role_data>();
192 workload.workloadClass = discord_core_internal::https_workload_class::Post;
193 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/roles";
194 parser.serializeJson<
true>(dataPackage, workload.content);
195 workload.callStack =
"roles::createGuildRoleAsync()";
196 if (dataPackage.
reason !=
"") {
197 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
200 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
203 newDataPackage.newPosition = dataPackage.
position;
204 newDataPackage.roleId = returnData.id;
206 for (
auto& value: results) {
207 if (value.id == returnData.id) {
211 co_return returnData;
215 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Guild_Role_Positions };
216 co_await newThreadAwaitable<jsonifier::vector<role_data>>();
219 for (
auto& value: currentRoles) {
220 if (value.id == newRole.
id) {
228 dataPackage.rolePositions.emplace_back(newData);
234 dataPackage.rolePositions.emplace_back(newData);
241 dataPackage.rolePositions.emplace_back(newDataPos);
242 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
243 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/roles";
244 parser.serializeJson<
true>(dataPackage, workload.content);
245 workload.callStack =
"roles::modifyGuildRolePositionsAsync()";
246 if (dataPackage.
reason !=
"") {
247 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
249 jsonifier::vector<role_data> returnData{};
250 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
251 co_return returnData;
255 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Guild_Role };
256 co_await newThreadAwaitable<role_data>();
257 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
258 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/roles/" + dataPackage.
roleId;
259 parser.serializeJson<
true>(dataPackage, workload.content);
260 workload.callStack =
"roles::modifyGuildRoleAsync()";
261 if (dataPackage.
reason !=
"") {
262 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
265 if (cache.contains(data.id)) {
266 data = cache[data.id];
268 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload), data);
269 if (doWeCacheRolesBool) {
276 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Guild_Role };
277 co_await newThreadAwaitable<void>();
278 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
279 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/roles/" + dataPackage.
roleId;
280 workload.callStack =
"roles::removeGuildRoleAsync()";
281 if (dataPackage.
reason !=
"") {
282 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
284 roles::httpsClient->submitWorkloadAndGetResult(std::move(workload));
289 co_await newThreadAwaitable<jsonifier::vector<role_data>>();
291 jsonifier::vector<role_data> rolesVectorNew{};
292 for (
auto& value: rolesVector) {
294 if (value2 == value.id) {
295 rolesVectorNew.emplace_back(value);
299 co_return std::move(rolesVectorNew);
303 co_await newThreadAwaitable<role_data>();
305 if (dataPackage.
guildId == 0) {
306 throw dca_exception{
"roles::getRoleAsync() error: sorry, but you forgot to set the guildId!" };
309 if (cache.contains(data.id)) {
310 data = cache[data.id];
312 for (
auto& value:
roles) {
313 if (value.id == dataPackage.
roleId) {
314 data = std::move(value);
317 if (doWeCacheRolesBool) {
324 if (cache.contains(dataPackage.
roleId)) {
325 return cache[dataPackage.
roleId];
335 bool roles::doWeCacheRoles() {
336 return roles::doWeCacheRolesBool;
339 discord_core_internal::https_client* roles::httpsClient{};
340 object_cache<role_cache_data> roles::cache{};
341 bool roles::doWeCacheRolesBool{};
A co_routine - representing a potentially asynchronous operation/function.
jsonifier::vector< snowflake > roles
Array of role object ids.
Data structure representing a single role_data.
jsonifier::string name
The role_data's name.
role_flags flags
Role_data flags.
uint32_t position
Its position amongst the rest of the guild's roles.
jsonifier::string unicodeEmoji
Emoji representing the role_data.
permissions permissionsVal
The role_data's base guild permissions.
uint32_t color
The role_data's color.
uint32_t position
Position of this role.
An interface class for the role_data related discord endpoints.
static co_routine< jsonifier::vector< role_data > > getGuildMemberRolesAsync(const get_guild_member_roles_data dataPackage)
Collects the roles that a guild_member has.
static co_routine< role_data > modifyGuildRoleAsync(const modify_guild_role_data dataPackage)
Updates a given role's properties.
static co_routine< void > addGuildMemberRoleAsync(const add_guild_member_role_data dataPackage)
Adds a role_data to a chosen guild member.
static co_routine< void > removeGuildRoleAsync(const remove_guild_role_data dataPackage)
Removes a given role from a guild.
static co_routine< jsonifier::vector< role_data > > modifyGuildRolePositionsAsync(modify_guild_role_positions_data dataPackage)
Updates a role_data's positions.
static co_routine< role_data > getRoleAsync(const get_role_data dataPackage)
Collects a role_data from the discord servers.
static co_routine< jsonifier::vector< role_data > > getGuildRolesAsync(const get_guild_roles_data dataPackage)
Collects the roles that a guild has.
static role_cache_data getCachedRole(const get_role_data dataPackage)
Collects a given role from the library's cache.
static co_routine< role_data > createGuildRoleAsync(const create_guild_role_data dataPackage)
Creates a new role_data within the given guild.
static co_routine< void > removeGuildMemberRoleAsync(const remove_guild_member_role_data dataPackage)
Removes a given role from a chosen guild_member_data.
uint64_t id
The snowflake id.
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.
uint32_t position
The position amongst the other roles.
snowflake guildId
Which guild to make the role_data in.
jsonifier::string reason
Reason for creating the role_data.
An exception class derived from std::runtime_error for dca-related exceptions.
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 reason
< reason for modifying the role_data.
snowflake roleId
The id of the role_data to update.
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.