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
28#ifndef GUILD_MEMBER_ENTITIES
29 #define GUILD_MEMBER_ENTITIES
30
34
35namespace DiscordCoreAPI {
36
37 inline Bool operator==(const DiscordCoreAPI::GuildMemberData& lhs, const DiscordCoreAPI::GuildMemberData& rhs) {
38 if ((lhs.guildId == rhs.guildId) && (lhs.id == rhs.id)) {
39 return true;
40 } else {
41 return false;
42 }
43 }
44
45 /**
46 * \addtogroup foundation_entities
47 * @{
48 */
49
50 /// For getting a GuildMember, from the library's cache or Discord server. \brief For getting a GuildMember, from the library's cache or Discord server.
51 struct DiscordCoreAPI_Dll GetGuildMemberData {
52 Snowflake guildMemberId{};///< The user id of the desired GuildMember.
53 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
54 };
55
56 /// For listing the GuildMembers of a chosen Guild. \brief For listing the GuildMembers of a chosen Guild.
57 struct DiscordCoreAPI_Dll ListGuildMembersData {
58 Snowflake guildId{};///< Guild from which to list the GuildMembers.
59 Snowflake after{};///< The highest user id in the previous page.
60 Int32 limit{ 0 };///< Max number of members to return (1 - 1000).
61 };
62
63 /// For searching for one or more GuildMembers within a chosen Guild. \brief For searching for one or more GuildMembers within a chosen Guild.
64 struct DiscordCoreAPI_Dll SearchGuildMembersData {
65 Snowflake guildId{};///< Guild within which to search for the GuildMembers.
66 String query{};///< Query String to match userName(s) and nickname(s) against.
67 Int32 limit{ 0 };///< Max number of members to return (1 - 1000).
68 };
69
70 /// For adding a new GuildMember to a chosen Guild. \brief For adding a new GuildMember to a chosen Guild.
71 struct DiscordCoreAPI_Dll AddGuildMemberData {
72 std::vector<Snowflake> roles{};///< Array of Role ids the member is assigned.
73 String accessToken{};///< An oauth2 access token granted with the guilds.join to the bot's application for the user you want to add.
74 Snowflake guildId{};///< The Guild to add the new GuildMember to.
75 Snowflake userId{};///< The User id of the user you wish to add.
76 String nick{};///< Value to set users nickname to.
77 Bool mute{};///< Whether the user is muted in voice channels.
78 Bool deaf{};///< Whether the user is deafened in voice channels.
79
80 operator JsonObject();
81 };
82
83 /// For modifying the Current GuildMember's values. \brief For modifying the current GuildMember's values.
84 struct DiscordCoreAPI_Dll ModifyCurrentGuildMemberData {
85 Snowflake guildId{};///< The Guild within which to modify the current user's values.
86 String reason{};///< A reason for modifying the current user's values.
87 String nick{};///< A new nickname for the current user.
88 };
89
90 /// For modifying a GuildMember's values. \brief For modifying a GuildMember's values.
91 struct DiscordCoreAPI_Dll ModifyGuildMemberData {
92 TimeStamp<std::chrono::milliseconds> communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
93 std::vector<Snowflake> roleIds{};///< A collection of Role id's to be applied to them.
94 Snowflake newVoiceChannelId{};///< The new voice Channel to move them into.
95 Snowflake currentChannelId{};///< The current voice Channel, if applicaple.
96 Snowflake guildMemberId{};///< The user id of the desired Guild memeber.
97 Snowflake guildId{};///< The id of the Guild for which you would like to modify a member.
98 String reason{};///< Reason for modifying this GuildMember.
99 String nick{};///< Their new display/nick name.
100 Bool mute{ false };///< Whether or not to mute them in voice.
101 Bool deaf{ false };///< Whether or not to deafen them, in voice.
102
103 operator JsonObject();
104 };
105
106 /// For removing a GuildMember from a chosen Guild. \brief For removing a GuildMember from a chosen Guild.
107 struct DiscordCoreAPI_Dll RemoveGuildMemberData {
108 Snowflake guildMemberId{};///< Id of the chosen GuildMember to kick.
109 Snowflake guildId{};///< Guild from which to kick the chosen GuildMember.
110 String reason{};///< Reason for kicking the GuildMember.
111 };
112
113 /// For timing out a GuildMember. \brief For timing out a GuildMember.
114 struct DiscordCoreAPI_Dll TimeoutGuildMemberData {
115 TimeoutDurations numOfMinutesToTimeoutFor{};///< The number of minutes to time-out the GuildMember for.
116 Snowflake guildMemberId{};///< The id of the GuildMember to be timed-out.
117 Snowflake guildId{};///< The id of the Guild from which you would like to acquire a member.
118 String reason{};///< Reason for timing them out.
119 };
120
121 /// A single GuildMember. \brief A single GuildMember.
122 class DiscordCoreAPI_Dll GuildMember : public GuildMemberData {
123 public:
124 TimeStamp<std::chrono::milliseconds> communicationDisabledUntil{};///< When the user's timeout will expire and the user will be able to communicate in the guild again.
125 String premiumSince{};///< If applicable, when they first boosted the server.
126
127 GuildMember() noexcept = default;
128
129 GuildMember& operator=(GuildMemberData&&) noexcept;
130
131 GuildMember(GuildMemberData&&) noexcept;
132
133 GuildMember& operator=(const GuildMemberData&) noexcept;
134
135 GuildMember(const GuildMemberData&) noexcept;
136
137 GuildMember(simdjson::ondemand::value jsonObjectData);
138
139 virtual ~GuildMember() noexcept = default;
140 };
141
142 class DiscordCoreAPI_Dll GuildMemberVector {
143 public:
144 GuildMemberVector() noexcept = default;
145
146 operator std::vector<GuildMember>();
147
148 GuildMemberVector(simdjson::ondemand::value jsonObjectData);
149
150 virtual ~GuildMemberVector() noexcept = default;
151
152 protected:
153 std::vector<GuildMember> theGuildMembers{};
154 };
155
156 /**@}*/
157
158
159 /**
160 * \addtogroup main_endpoints
161 * @{
162 */
163 /// An interface class for the GuildMember related Discord endpoints. \brief An interface class for the GuildMember related Discord endpoints.
164 class DiscordCoreAPI_Dll GuildMembers {
165 public:
166 friend class DiscordCoreInternal::WebSocketSSLShard;
167 friend class DiscordCoreClient;
168 friend class GuildMemberData;
169 friend class GuildData;
170 friend class Guild;
171
172 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManagerNew);
173
174 /// Collects a GuildMember from the Discord servers. \brief Collects a GuildMember from the Discord servers.
175 /// \param dataPackage A GetGuildMemberData structure.
176 /// \returns A CoRoutine containing a GuildMember.
177 static CoRoutine<GuildMember> getGuildMemberAsync(GetGuildMemberData dataPackage);
178
179 /// Collects a GuildMember from the library's cache. \brief Collects a GuildMember from the library's cache.
180 /// \param dataPackage A GetGuildMemberData structure.
181 /// \returns A CoRoutine containing a GuildMember.
182 static CoRoutine<GuildMemberData> getCachedGuildMemberAsync(GetGuildMemberData dataPackage);
183
184 /// Lists all of the GuildMembers of a chosen Guild. \brief Lists all of the GuildMembers of a chosen Guild.
185 /// \param dataPackage A ListGuildMembersData structure.
186 /// \returns A CoRoutine containing a vector<GuildMembers>.
187 static CoRoutine<std::vector<GuildMember>> listGuildMembersAsync(ListGuildMembersData dataPackage);
188
189 /// Searches for a list of GuildMembers of a chosen Guild. \brief Searches for a list of GuildMembers of a chosen Guild.
190 /// \param dataPackage A SearchGuildMembersData structure.
191 /// \returns A CoRoutine containing a vector<GuildMembers>.
192 static CoRoutine<std::vector<GuildMember>> searchGuildMembersAsync(SearchGuildMembersData dataPackage);
193
194 /// Adds a GuildMember to a chosen Guild. \brief Adds a GuildMember to a chosen Guild.
195 /// \param dataPackage An AddGuildMemberData structure.
196 /// \returns A CoRoutine containing a vector<GuildMembers>.
197 static CoRoutine<GuildMember> addGuildMemberAsync(AddGuildMemberData dataPackage);
198
199 /// Modifies a GuildMember's properties. \brief Modifies a GuildMember's properties.
200 /// \param dataPackage A ModifyGuildMemberData structure.
201 /// \returns A CoRoutine containing a GuildMember.
202 static CoRoutine<GuildMember> modifyGuildMemberAsync(ModifyGuildMemberData dataPackage);
203
204 /// Modifies the current GuildMember's properties. \brief Modifies the current GuildMember's properties.
205 /// \param dataPackage A ModifyCurrentGuildMemberData structure.
206 /// \returns A CoRoutine containing a GuildMember.
207 static CoRoutine<GuildMember> modifyCurrentGuildMemberAsync(ModifyCurrentGuildMemberData dataPackage);
208
209 /// Removes a chosen GuildMember from a chosen Guild. \brief Removes a chosen GuildMember from a chosen Guild.
210 /// \param dataPackage A RemoveGuildMemberData structure.
211 /// \returns A CoRoutine containing void.
212 static CoRoutine<void> removeGuildMemberAsync(RemoveGuildMemberData dataPackage);
213
214 /// Times-out a chosen GuildMember from a chosen Guild. \brief Times-out a chosen GuildMember from a chosen Guild.
215 /// \param dataPackage A TimeoutGuildMemberData structure.
216 /// \returns A CoRoutine containing GuildMember.
217 static CoRoutine<GuildMember> timeoutGuildMemberAsync(TimeoutGuildMemberData dataPackage);
218
219 static void insertGuildMember(GuildMemberData guildMember);
220
221 static void removeGuildMember(GuildMemberData guildMemberId);
222
223 protected:
224 static DiscordCoreInternal::HttpsClient* httpsClient;
225 static ObjectCache<GuildMemberData> cache;
226 static Bool doWeCacheGuildMembers;
227 };
228 /**@}*/
229};// namespace DiscordCoreAPI
230#endif
TimeoutDurations
Timeout durations for the timeout command.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:62
DiscordCoreClient - The main class for this library.
Data structure representing a single GuildMember. Data structure representing a single Guild.
Snowflake guildId
The current Guild's id.
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:976