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 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
3
4 Copyright 2021, 2022 Chris M. (RealTimeChris)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
20*/
21/// GuildMemberEntities.hpp - Header for the GuildMember related classes and
22/// structs. May 13, 2021 Chris M.
23/// https://discordcoreapi.com
24/// \file GuildMemberEntities.hpp
25
26#pragma once
27
31
32namespace DiscordCoreAPI {
33
34 DiscordCoreAPI_Dll inline bool operator==(const VoiceStateDataLight& lhs, const VoiceStateDataLight& rhs) {
35 return (lhs.guildId == rhs.guildId) && (lhs.userId == rhs.userId);
36 }
37
38 DiscordCoreAPI_Dll inline bool operator==(const GuildMemberData& lhs, const GuildMemberData& rhs) {
39 return (lhs.guildId == rhs.guildId) && (lhs.id == rhs.id);
40 }
41
42 /**
43 * \addtogroup foundation_entities
44 * @{
45 */
46
47 /// \brief For getting a GuildMember, from the library's cache or Discord server.
48 struct DiscordCoreAPI_Dll GetGuildMemberData {
49 Snowflake guildMemberId{};///< The user id of the desired GuildMember.
50 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
51 };
52
53 /// \brief For listing the GuildMembers of a chosen Guild.
54 struct DiscordCoreAPI_Dll ListGuildMembersData {
55 Snowflake guildId{};///< Guild from which to list the GuildMembers.
56 Snowflake after{};///< The highest user id in the previous page.
57 int32_t limit{};///< Max number of members to return (1 - 1000).
58 };
59
60 /// \brief For searching for one or more GuildMembers within a chosen Guild.
61 struct DiscordCoreAPI_Dll SearchGuildMembersData {
62 Snowflake guildId{};///< Guild within which to search for the GuildMembers.
63 std::string query{};///< Query std::string to match userName(s) and nickname(s) against.
64 int32_t limit{};///< Max number of members to return (1 - 1000).
65 };
66
67 /// \brief For adding a new GuildMember to a chosen Guild.
68 struct DiscordCoreAPI_Dll AddGuildMemberData {
69 std::vector<Snowflake> roles{};///< Array of Role ids the member is assigned.
70 std::string accessToken{};///< An oauth2 access token granted with the guilds.join to the bot's application for the user you want to add.
71 Snowflake guildId{};///< The Guild to add the new GuildMember to.
72 Snowflake userId{};///< The User id of the user you wish to add.
73 std::string nick{};///< Value to set users nickname to.
74 bool mute{};///< Whether the user is muted in voice channels.
75 bool deaf{};///< Whether the user is deafened in voice channels.
76
77 operator Jsonifier();
78 };
79
80 /// \brief For modifying the current GuildMember's values.
81 struct DiscordCoreAPI_Dll ModifyCurrentGuildMemberData {
82 std::string reason{};///< A reason for modifying the current user's values.
83 Snowflake guildId{};///< The Guild within which to modify the current user's values.
84 std::string nick{};///< A new nickname for the current user.
85 };
86
87 /// \brief For modifying a GuildMember's values.
88 struct DiscordCoreAPI_Dll ModifyGuildMemberData {
89 TimeStamp communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
90 std::vector<Snowflake> roleIds{};///< A collection of Role id's to be applied to them.
91 Snowflake newVoiceChannelId{};///< The new voice Channel to move them into.
92 Snowflake currentChannelId{};///< The current voice Channel, if applicaple.
93 Snowflake guildMemberId{};///< The user id of the desired Guild memeber.
94 Snowflake guildId{};///< The id of the Guild for which you would like to modify a member.
95 std::string reason{};///< Reason for modifying this GuildMember.
96 std::string nick{};///< Their new display/nick name.
97 bool mute{};///< Whether or not to mute them in voice.
98 bool deaf{};///< Whether or not to deafen them, in voice.
99
100 operator Jsonifier();
101 };
102
103 /// \brief For removing a GuildMember from a chosen Guild.
104 struct DiscordCoreAPI_Dll RemoveGuildMemberData {
105 Snowflake guildMemberId{};///< Id of the chosen GuildMember to kick.
106 std::string reason{};///< Reason for kicking the GuildMember.
107 Snowflake guildId{};///< Guild from which to kick the chosen GuildMember.
108 };
109
110 /// \brief For timing out a GuildMember.
111 struct DiscordCoreAPI_Dll TimeoutGuildMemberData {
112 TimeoutDurations numOfMinutesToTimeoutFor{};///< The number of minutes to time-out the GuildMember for.
113 Snowflake guildMemberId{};///< The id of the GuildMember to be timed-out.
114 std::string reason{};///< Reason for timing them out.
115 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
116 };
117
118 /// \brief A single GuildMember.
119 class DiscordCoreAPI_Dll GuildMember : public GuildMemberData {
120 public:
121 TimeStamp communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
122 std::string premiumSince{};///< If applicable, when they first boosted the server.
123
124 GuildMember() noexcept = default;
125
126 GuildMember& operator=(GuildMemberData&&) noexcept;
127
128 GuildMember(GuildMemberData&&) noexcept;
129
130 GuildMember& operator=(const GuildMemberData&) noexcept;
131
132 GuildMember(const GuildMemberData&) noexcept;
133
134 GuildMember(simdjson::ondemand::value jsonObjectData);
135
136 virtual ~GuildMember() noexcept = default;
137 };
138
139 class DiscordCoreAPI_Dll GuildMemberVector {
140 public:
141 GuildMemberVector() noexcept = default;
142
143 operator std::vector<GuildMember>();
144
145 GuildMemberVector(simdjson::ondemand::value jsonObjectData);
146
147 virtual ~GuildMemberVector() noexcept = default;
148
149 protected:
150 std::vector<GuildMember> guildMembers{};
151 };
152
153 /**@}*/
154
155
156 /**
157 * \addtogroup main_endpoints
158 * @{
159 */
160 /// \brief An interface class for the GuildMember related Discord endpoints.
161 class DiscordCoreAPI_Dll GuildMembers {
162 public:
163 friend class DiscordCoreInternal::WebSocketClient;
164 friend class DiscordCoreClient;
165 friend class GuildMemberData;
166 friend class GuildData;
167 friend class Guild;
168
169 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManagerNew);
170
171 /// \brief Collects a GuildMember from the Discord servers.
172 /// \param dataPackage A GetGuildMemberData structure.
173 /// \returns A CoRoutine containing a GuildMember.
174 static CoRoutine<GuildMember> getGuildMemberAsync(GetGuildMemberData dataPackage);
175
176 /// \brief Collects a GuildMember from the library's cache.
177 /// \param dataPackage A GetGuildMemberData structure.
178 /// \returns A CoRoutine containing a GuildMember.
179 static GuildMemberData getCachedGuildMember(GetGuildMemberData dataPackage);
180
181 /// \brief Lists all of the GuildMembers of a chosen Guild.
182 /// \param dataPackage A ListGuildMembersData structure.
183 /// \returns A CoRoutine containing a vector<GuildMembers>.
184 static CoRoutine<std::vector<GuildMember>> listGuildMembersAsync(ListGuildMembersData dataPackage);
185
186 /// \brief Searches for a list of GuildMembers of a chosen Guild.
187 /// \param dataPackage A SearchGuildMembersData structure.
188 /// \returns A CoRoutine containing a vector<GuildMembers>.
189 static CoRoutine<std::vector<GuildMember>> searchGuildMembersAsync(SearchGuildMembersData dataPackage);
190
191 /// \brief Adds a GuildMember to a chosen Guild.
192 /// \param dataPackage An AddGuildMemberData structure.
193 /// \returns A CoRoutine containing a vector<GuildMembers>.
194 static CoRoutine<GuildMember> addGuildMemberAsync(AddGuildMemberData dataPackage);
195
196 /// \brief Modifies a GuildMember's properties.
197 /// \param dataPackage A ModifyGuildMemberData structure.
198 /// \returns A CoRoutine containing a GuildMember.
199 static CoRoutine<GuildMember> modifyGuildMemberAsync(ModifyGuildMemberData dataPackage);
200
201 /// \brief Modifies the current GuildMember's properties.
202 /// \param dataPackage A ModifyCurrentGuildMemberData structure.
203 /// \returns A CoRoutine containing a GuildMember.
204 static CoRoutine<GuildMember> modifyCurrentGuildMemberAsync(ModifyCurrentGuildMemberData dataPackage);
205
206 /// \brief Removes a chosen GuildMember from a chosen Guild.
207 /// \param dataPackage A RemoveGuildMemberData structure.
208 /// \returns A CoRoutine containing void.
209 static CoRoutine<void> removeGuildMemberAsync(RemoveGuildMemberData dataPackage);
210
211 /// \brief Times-out a chosen GuildMember from a chosen Guild.
212 /// \param dataPackage A TimeoutGuildMemberData structure.
213 /// \returns A CoRoutine containing GuildMember.
214 static CoRoutine<GuildMember> timeoutGuildMemberAsync(TimeoutGuildMemberData dataPackage);
215
216 static ObjectCache<VoiceStateDataLight>& getVsCache();
217
218 static ObjectCache<GuildMemberData>& getCache();
219
220 static void insertVoiceState(VoiceStateData voiceState);
221
222 static void removeVoiceState(VoiceStateData voiceState);
223
224 static void insertGuildMember(GuildMemberData guildMember);
225
226 static void removeGuildMember(GuildMemberData guildMemberId);
227
228 static bool doWeCacheGuildMembers();
229
230 protected:
231 static DiscordCoreInternal::HttpsClient* httpsClient;
232 static ObjectCache<VoiceStateDataLight> vsCache;
233 static ObjectCache<GuildMemberData> cache;
234 static bool doWeCacheGuildMembersBool;
235 };
236 /**@}*/
237};// namespace DiscordCoreAPI
TimeoutDurations
Timeout durations for the timeout command.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:59
DiscordCoreClient - The main class for this library.
Data structure representing a single GuildMember.
Data structure representing a single Guild.
A discord Guild. Used to connect to/disconnect from voice.
For getting a GuildMember, from the library's cache or Discord server.
For listing the GuildMembers of a chosen Guild.
For searching for one or more GuildMembers within a chosen Guild.
For adding a new GuildMember to a chosen Guild.
For modifying the current GuildMember's values.
For modifying a GuildMember's values.
For removing a GuildMember from a chosen Guild.
An interface class for the GuildMember related Discord endpoints.
Class for representing a timeStamp, as well as working with time-related values.
Definition: Utilities.hpp:1576