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 GuildMemberData related classes and
27/// structs. May 13, 2021 Chris M.
28/// https://discordcoreapi.com
29/// \file GuildMemberEntities.hpp
30
31#pragma once
32
37
38namespace DiscordCoreAPI {
39
40 /**
41 * \addtogroup foundation_entities
42 * @{
43 */
44
45 /// @brief For getting a GuildMember, from the library's cache or Discord server.
47 Snowflake guildMemberId{};///< The user id of the desired GuildMemberData.
48 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
49 };
50
51 /// @brief For listing the GuildMembers of a chosen Guild.
53 Snowflake guildId{};///< Guild from which to list the GuildMembers.
54 Snowflake after{};///< The highest user id in the previous page.
55 int32_t limit{};///< Max number of members to return (1 - 1000).
56 };
57
58 /// @brief For searching for one or more GuildMembers within a chosen Guild.
60 Snowflake guildId{};///< Guild within which to search for the GuildMembers.
61 std::string query{};///< Query std::string to match username(s) and nickname(s) against.
62 int32_t limit{};///< Max number of members to return (1 - 1000).
63 };
64
65 /// @brief For adding a new GuildMemberData to a chosen Guild.
67 jsonifier::vector<Snowflake> roles{};///< Array of RoleData ids the member is assigned.
68 std::string accessToken{};///< An oauth2 access token granted with the guilds.join to the bot's application for the user you want to add.
69 Snowflake guildId{};///< The Guild to add the new GuildMemberData to.
70 Snowflake userId{};///< The UserData id of the user you wish to add.
71 std::string nick{};///< Value to set users nickname to.
72 bool mute{};///< Whether the user is muted in voice channels.
73 bool deaf{};///< Whether the user is deafened in voice channels.
74 };
75
76 /// @brief For modifying the current GuildMemberData's values.
78 std::string reason{};///< A reason for modifying the current user's values.
79 Snowflake guildId{};///< The Guild within which to modify the current user's values.
80 std::string nick{};///< A new nickname for the current user.
81 };
82
83 /// @brief For modifying a GuildMember's values.
85 std::string communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
86 jsonifier::vector<Snowflake> roleIds{};///< A collection of RoleData id's to be applied to them.
87 Snowflake newVoiceChannelId{};///< The new voice ChannelData to move them into.
88 Snowflake currentChannelId{};///< The current voice ChannelData, if applicaple.
89 Snowflake guildMemberId{};///< The user id of the desired Guild memeber.
90 Snowflake guildId{};///< The id of the Guild for which you would like to modify a member.
91 std::string reason{};///< Reason for modifying this GuildMemberData.
92 std::string nick{};///< Their new display/nick name.
93 bool mute{};///< Whether or not to mute them in voice.
94 bool deaf{};///< Whether or not to deafen them, in voice.
95 };
96
97 /// @brief For removing a GuildMember from a chosen Guild.
99 Snowflake guildMemberId{};///< Snowflake of the chosen GuildMemberData to kick.
100 std::string reason{};///< Reason for kicking the GuildMemberData.
101 Snowflake guildId{};///< Guild from which to kick the chosen GuildMemberData.
102 };
103
104 /// @brief For timing out a GuildMember.
106 TimeoutDurations numOfMinutesToTimeoutFor{};///< The number of minutes to time-out the GuildMemberData for.
107 Snowflake guildMemberId{};///< The id of the GuildMemberData to be timed-out.
108 std::string reason{};///< Reason for timing them out.
109 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
110 };
111
112 /**@}*/
113
114
115 /**
116 * \addtogroup main_endpoints
117 * @{
118 */
119 /// @brief An interface class for the GuildMemberData related Discord endpoints.
120 class DiscordCoreAPI_Dll GuildMembers {
121 public:
122 friend class DiscordCoreInternal::WebSocketClient;
123 friend class DiscordCoreClient;
124 friend class GuildMemberData;
125 friend class GuildData;
126 friend class Guild;
127
128 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManagerNew);
129
130 /// @brief Collects a GuildMember from the Discord servers.
131 /// @param dataPackage A GetGuildMemberData structure.
132 /// @return A CoRoutine containing a GuildMember.
133 static CoRoutine<GuildMemberData> getGuildMemberAsync(GetGuildMemberData dataPackage);
134
135 /// @brief Collects a GuildMember from the library's cache.
136 /// @param dataPackage A GetGuildMemberData structure.
137 /// @return A CoRoutine containing a GuildMember.
138 static GuildMemberCacheData getCachedGuildMember(GetGuildMemberData dataPackage);
139
140 /// @brief Lists all of the GuildMembers of a chosen Guild.
141 /// @param dataPackage A ListGuildMembersData structure.
142 /// @return A CoRoutine containing a vector<GuildMembers>.
143 static CoRoutine<jsonifier::vector<GuildMemberData>> listGuildMembersAsync(ListGuildMembersData dataPackage);
144
145 /// @brief Searches for a list of GuildMembers of a chosen Guild.
146 /// @param dataPackage A SearchGuildMembersData structure.
147 /// @return A CoRoutine containing a vector<GuildMembers>.
148 static CoRoutine<jsonifier::vector<GuildMemberData>> searchGuildMembersAsync(SearchGuildMembersData dataPackage);
149
150 /// @brief Adds a GuildMember to a chosen Guild.
151 /// @param dataPackage An AddGuildMemberData structure.
152 /// @return A CoRoutine containing a vector<GuildMembers>.
153 static CoRoutine<GuildMemberData> addGuildMemberAsync(AddGuildMemberData dataPackage);
154
155 /// @brief Modifies a GuildMember's properties.
156 /// @param dataPackage A ModifyGuildMemberData structure.
157 /// @return A CoRoutine containing a GuildMember.
158 static CoRoutine<GuildMemberData> modifyGuildMemberAsync(ModifyGuildMemberData dataPackage);
159
160 /// @brief Modifies the current GuildMemberData's properties.
161 /// @param dataPackage A ModifyCurrentGuildMemberData structure.
162 /// @return A CoRoutine containing a GuildMember.
163 static CoRoutine<GuildMemberData> modifyCurrentGuildMemberAsync(ModifyCurrentGuildMemberData dataPackage);
164
165 /// @brief Removes a chosen GuildMemberData from a chosen Guild.
166 /// @param dataPackage A RemoveGuildMemberData structure.
167 /// @return A CoRoutine containing void.
168 static CoRoutine<void> removeGuildMemberAsync(RemoveGuildMemberData dataPackage);
169
170 /// @brief Times-out a chosen GuildMemberData from a chosen Guild.
171 /// @param dataPackage A TimeoutGuildMemberData structure.
172 /// @return A CoRoutine containing GuildMemberData.
173 static CoRoutine<GuildMemberData> timeoutGuildMemberAsync(TimeoutGuildMemberData dataPackage);
174
175 template<typename VoiceStateType> static inline VoiceStateDataLight& insertVoiceState(VoiceStateType&& voiceState) {
176 if (voiceState.userId == 0) {
177 throw DCAException{ "Sorry, but there was no id set for that voice state." };
178 }
179 return **vsCache.emplace(std::forward<VoiceStateType>(voiceState));
180 }
181
182 template<typename GuildMemberType> static inline void insertGuildMember(GuildMemberType&& guildMember) {
183 if (doWeCacheGuildMembersBool) {
184 if (guildMember.guildId == 0 || guildMember.user.id == 0) {
185 throw DCAException{ "Sorry, but there was no id set for that guildmember." };
186 }
187 cache.emplace(static_cast<GuildMemberCacheData>(std::forward<GuildMemberType>(guildMember)));
188 }
189 }
190
191 static VoiceStateDataLight getVoiceStateData(const TwoIdKey& voiceState);
192
193 static void removeGuildMember(const TwoIdKey& guildMemberId);
194
195 static void removeVoiceState(const TwoIdKey& voiceState);
196
197 static bool doWeCacheGuildMembers();
198
199 protected:
200 static DiscordCoreInternal::HttpsClient* httpsClient;
203 static bool doWeCacheGuildMembersBool;
204 };
205 /**@}*/
206};
TimeoutDurations
Timeout durations for the timeout command.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:88
DiscordCoreClient - The main class for this library.
Data structure representing a single GuildMemberData.
Data structure representing a single GuildMemberData.
A discord Guild. Used to connect to/disconnect from voice.
For getting a GuildMember, from the library's cache or Discord server.
Snowflake guildId
The id of the Guild from which you would like to acquire a member.
Snowflake guildMemberId
The user id of the desired GuildMemberData.
For listing the GuildMembers of a chosen Guild.
int32_t limit
Max number of members to return (1 - 1000).
Snowflake guildId
Guild from which to list the GuildMembers.
Snowflake after
The highest user id in the previous page.
For searching for one or more GuildMembers within a chosen Guild.
Snowflake guildId
Guild within which to search for the GuildMembers.
int32_t limit
Max number of members to return (1 - 1000).
std::string query
Query std::string to match username(s) and nickname(s) against.
For adding a new GuildMemberData to a chosen Guild.
Snowflake userId
The UserData id of the user you wish to add.
std::string accessToken
An oauth2 access token granted with the guilds.join to the bot's application for the user you want to...
bool mute
Whether the user is muted in voice channels.
bool deaf
Whether the user is deafened in voice channels.
jsonifier::vector< Snowflake > roles
Array of RoleData ids the member is assigned.
Snowflake guildId
The Guild to add the new GuildMemberData to.
std::string nick
Value to set users nickname to.
For modifying the current GuildMemberData's values.
std::string reason
A reason for modifying the current user's values.
Snowflake guildId
The Guild within which to modify the current user's values.
std::string nick
A new nickname for the current user.
For modifying a GuildMember's values.
std::string communicationDisabledUntil
When the user's timeout will expire and the user will be able to communicate in the guild again.
std::string reason
Reason for modifying this GuildMemberData.
bool mute
Whether or not to mute them in voice.
jsonifier::vector< Snowflake > roleIds
A collection of RoleData id's to be applied to them.
bool deaf
Whether or not to deafen them, in voice.
Snowflake guildId
The id of the Guild for which you would like to modify a member.
std::string nick
Their new display/nick name.
Snowflake currentChannelId
The current voice ChannelData, if applicaple.
Snowflake newVoiceChannelId
The new voice ChannelData to move them into.
Snowflake guildMemberId
The user id of the desired Guild memeber.
For removing a GuildMember from a chosen Guild.
std::string reason
Reason for kicking the GuildMemberData.
Snowflake guildMemberId
Snowflake of the chosen GuildMemberData to kick.
Snowflake guildId
Guild from which to kick the chosen GuildMemberData.
Snowflake guildId
The id of the Guild from which you would like to acquire a member.
Snowflake guildMemberId
The id of the GuildMemberData to be timed-out.
std::string reason
Reason for timing them out.
TimeoutDurations numOfMinutesToTimeoutFor
The number of minutes to time-out the GuildMemberData for.
An interface class for the GuildMemberData 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