DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
GuildMemberEntities.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/// GuildMemberEntities.hpp - Header for the guild_member_data related classes and
27/// structs. may 13, 2021 Chris M.
28/// https://discordcoreapi.com
29/// \file GuildMemberEntities.hpp
30
31#pragma once
32
37#include <unordered_set>
38
39namespace discord_core_api {
40
41 /**
42 * \addtogroup foundation_entities
43 * @{
44 */
45
46 /// @brief For getting a guild_member, from the library's cache or discord server.
48 snowflake guildMemberId{};///< The user id of the desired guild_member_data.
49 snowflake guildId{};///< The id of the guild from which you would like to acquire a member.
50 };
51
52 /// @brief For listing the guild_members of a chosen guild.
54 snowflake guildId{};///< Guild from which to list the guild_members.
55 snowflake after{};///< The highest user id in the previous page.
56 int32_t limit{};///< Max number of members to return (1 - 1000).
57 };
58
59 /// @brief For searching for one or more guild_members within a chosen guild.
61 snowflake guildId{};///< Guild within which to search for the guild_members.
62 jsonifier::string query{};///< Query jsonifier::string to match username(s) and nickname(s) against.
63 int32_t limit{};///< Max number of members to return (1 - 1000).
64 };
65
66 /// @brief For adding a new guild_member_data to a chosen guild.
68 jsonifier::vector<snowflake> roles{};///< Array of role_data ids the member is assigned.
69 jsonifier::string accessToken{};///< An oauth2 access token granted with the guilds.join to the bot's application for the user you want to add.
70 snowflake guildId{};///< The guild to add the new guild_member_data to.
71 snowflake userId{};///< The user_data id of the user you wish to add.
72 jsonifier::string nick{};///< Value to set users nickname to.
73 bool mute{};///< Whether the user is muted in voice channels.
74 bool deaf{};///< Whether the user is deafened in voice channels.
75 };
76
77 /// @brief For modifying the current guild_member_data's values.
79 jsonifier::string reason{};///< A reason for modifying the current user's values.
80 snowflake guildId{};///< The guild within which to modify the current user's values.
81 jsonifier::string nick{};///< A new nickname for the current user.
82 };
83
84 /// @brief For modifying a guild_member's values.
85 struct DiscordCoreAPI_Dll modify_guild_member_data {
86 modify_guild_member_data(const guild_member_data& other);
87 std::unordered_set<jsonifier::string> jsonifierExcludedKeys{};
88 jsonifier::string communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
89 jsonifier::vector<snowflake> roleIds{};///< A collection of role_data id's to be applied to them.
90 jsonifier::string reason{};///< Reason for modifying this guild_member_data.
91 snowflake guildMemberId{};///< The user id of the desired guild memeber.
92 jsonifier::string nick{};///< Their new display/nick name.
93 snowflake channelId{};///< The current voice channel_data, if applicaple.
94 snowflake guildId{};///< The id of the guild for which you would like to modify a member.
95 uint32_t flags{};
96 bool mute{};///< Whether or not to mute them in voice.
97 bool deaf{};///< Whether or not to deafen them, in voice.
98 };
99
100 /// @brief For removing a guild_member from a chosen guild.
102 snowflake guildMemberId{};///< snowflake of the chosen guild_member_data to kick.
103 jsonifier::string reason{};///< Reason for kicking the guild_member_data.
104 snowflake guildId{};///< Guild from which to kick the chosen guild_member_data.
105 };
106
107 /// @brief For timing out a guild_member.
109 timeout_durations numOfMinutesToTimeoutFor{};///< The number of minutes to time-out the guild_member_data for.
110 snowflake guildMemberId{};///< The id of the guild_member_data to be timed-out.
111 jsonifier::string reason{};///< Reason for timing them out.
112 snowflake guildId{};///< The id of the guild from which you would like to acquire a member.
113 };
114
115 /**@}*/
116
117
118 /**
119 * \addtogroup main_endpoints
120 * @{
121 */
122 /// @brief An interface class for the guild_member_data related discord endpoints.
123 class DiscordCoreAPI_Dll guild_members {
124 public:
125 friend class discord_core_internal::websocket_client;
126 friend class discord_core_client;
127 friend class guild_member_data;
128 friend class guild_data;
129 friend class guild;
130
131 static void initialize(discord_core_internal::https_client*, config_manager* configManagerNew);
132
133 /// @brief Collects a guild_member from the discord servers.
134 /// @param dataPackage a get_guild_member_data structure.
135 /// @return a co_routine containing a guild_member.
136 static co_routine<guild_member_data> getGuildMemberAsync(get_guild_member_data dataPackage);
137
138 /// @brief Collects a guild_member from the library's cache.
139 /// @param dataPackage a get_guild_member_data structure.
140 /// @return a co_routine containing a guild_member.
141 static guild_member_cache_data getCachedGuildMember(get_guild_member_data dataPackage);
142
143 /// @brief Lists all of the guild_members of a chosen guild.
144 /// @param dataPackage a list_guild_members_data structure.
145 /// @return a co_routine containing a vector<guild_members>.
146 static co_routine<jsonifier::vector<guild_member_data>> listGuildMembersAsync(list_guild_members_data dataPackage);
147
148 /// @brief Searches for a list of guild_members of a chosen guild.
149 /// @param dataPackage a search_guild_members_data structure.
150 /// @return a co_routine containing a vector<guild_members>.
151 static co_routine<jsonifier::vector<guild_member_data>> searchGuildMembersAsync(search_guild_members_data dataPackage);
152
153 /// @brief Adds a guild_member to a chosen guild.
154 /// @param dataPackage an add_guild_member_data structure.
155 /// @return a co_routine containing a vector<guild_members>.
156 static co_routine<guild_member_data> addGuildMemberAsync(add_guild_member_data dataPackage);
157
158 /// @brief Modifies a guild_member's properties.
159 /// @param dataPackage a modify_guild_member_data structure.
160 /// @return a co_routine containing a guild_member.
161 static co_routine<guild_member_data> modifyGuildMemberAsync(modify_guild_member_data dataPackage);
162
163 /// @brief Modifies the current guild_member_data's properties.
164 /// @param dataPackage a modify_current_guild_member_data structure.
165 /// @return a co_routine containing a guild_member.
166 static co_routine<guild_member_data> modifyCurrentGuildMemberAsync(modify_current_guild_member_data dataPackage);
167
168 /// @brief Removes a chosen guild_member_data from a chosen guild.
169 /// @param dataPackage a remove_guild_member_data structure.
170 /// @return a co_routine containing void.
171 static co_routine<void> removeGuildMemberAsync(remove_guild_member_data dataPackage);
172
173 /// @brief Times-out a chosen guild_member_data from a chosen guild.
174 /// @param dataPackage a timeout_guild_member_data structure.
175 /// @return a co_routine containing guild_member_data.
176 static co_routine<guild_member_data> timeoutGuildMemberAsync(timeout_guild_member_data dataPackage);
177
178 template<typename voice_state_type> DCA_INLINE static void insertVoiceState(voice_state_type&& voiceState) {
179 if (doWeCacheVoiceStatesBool) {
180 if (voiceState.userId == 0) {
181 throw dca_exception{ "Sorry, but there was no id set for that voice state." };
182 }
183 vsCache.emplace(std::forward<voice_state_type>(voiceState));
184 }
185 }
186
187 template<typename guild_member_type> DCA_INLINE static void insertGuildMember(guild_member_type&& guildMember) {
188 if (doWeCacheGuildMembersBool) {
189 if (guildMember.guildId == 0 || guildMember.user.id == 0) {
190 throw dca_exception{ "Sorry, but there was no id set for that guildmember." };
191 }
192 cache.emplace(static_cast<guild_member_cache_data>(std::forward<guild_member_type>(guildMember)));
193 }
194 }
195
196 /// @brief Collect a given guild_member's voice state data.
197 /// @param voiceState A two-id-key representing their user-id and guild-id.
198 /// @return voice_state_data_light The guild_member's voice_state_data.
199 static voice_state_data_light getVoiceStateData(const two_id_key& voiceState);
200
201 static void removeGuildMember(const two_id_key& guildMemberId);
202
203 static void removeVoiceState(const two_id_key& voiceState);
204
205 static bool doWeCacheGuildMembers();
206
207 static bool doWeCacheVoiceStates();
208
209 protected:
210 static discord_core_internal::https_client* httpsClient;
211 static object_cache<voice_state_data_light> vsCache;
212 static object_cache<guild_member_cache_data> cache;
213 static bool doWeCacheGuildMembersBool;
214 static bool doWeCacheVoiceStatesBool;
215 };
216 /**@}*/
217};
An interface class for the guild_member_data related discord endpoints.
timeout_durations
Timeout durations for the timeout command.
The main namespace for the forward-facing interfaces.
For adding a new guild_member_data to a chosen guild.
snowflake userId
The user_data id of the user you wish to add.
jsonifier::string nick
Value to set users nickname to.
bool mute
Whether the user is muted in voice channels.
jsonifier::vector< snowflake > roles
Array of role_data ids the member is assigned.
bool deaf
Whether the user is deafened in voice channels.
jsonifier::string accessToken
An oauth2 access token granted with the guilds.join to the bot's application for the user you want to...
snowflake guildId
The guild to add the new guild_member_data to.
For getting a guild_member, from the library's cache or discord server.
snowflake guildMemberId
The user id of the desired guild_member_data.
snowflake guildId
The id of the guild from which you would like to acquire a member.
For listing the guild_members of a chosen guild.
snowflake after
The highest user id in the previous page.
int32_t limit
Max number of members to return (1 - 1000).
snowflake guildId
Guild from which to list the guild_members.
For modifying the current guild_member_data's values.
jsonifier::string nick
A new nickname for the current user.
jsonifier::string reason
A reason for modifying the current user's values.
snowflake guildId
The guild within which to modify the current user's values.
For modifying a guild_member's values.
For removing a guild_member from a chosen guild.
snowflake guildMemberId
snowflake of the chosen guild_member_data to kick.
snowflake guildId
Guild from which to kick the chosen guild_member_data.
jsonifier::string reason
Reason for kicking the guild_member_data.
For searching for one or more guild_members within a chosen guild.
int32_t limit
Max number of members to return (1 - 1000).
snowflake guildId
Guild within which to search for the guild_members.
jsonifier::string query
Query jsonifier::string to match username(s) and nickname(s) against.
jsonifier::string reason
Reason for timing them out.
snowflake guildMemberId
The id of the guild_member_data to be timed-out.
snowflake guildId
The id of the guild from which you would like to acquire a member.
timeout_durations numOfMinutesToTimeoutFor
The number of minutes to time-out the guild_member_data for.