DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
UserEntities.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/// UserEntities.hpp - Header for User related classes and structs.
22/// May 13, 2021
23/// https://discordcoreapi.com
24/// \file UserEntities.hpp
25
26#pragma once
27
30
31namespace DiscordCoreAPI {
32
33 DiscordCoreAPI_Dll inline bool operator==(const UserData& lhs, const UserData& rhs) {
34 return lhs.id == rhs.id;
35 }
36
37 /**
38 * \addtogroup foundation_entities
39 * @{
40 */
41
42 /// \brief For adding a user to a group DM.
43 struct DiscordCoreAPI_Dll AddRecipientToGroupDMData {
44 Snowflake channelId{};///< The Channel Id of the DM.
45 std::string token{};///< The user's access token.
46 std::string nick{};///< The user's nickname.
47 Snowflake userId{};///< The user's Id.
48
49 operator Jsonifier();
50 };
51
52 /// \brief For removing a User from a group DM.
53 struct DiscordCoreAPI_Dll RemoveRecipientFromGroupDMData {
54 Snowflake channelId{};///< The Channel Id of the DM.
55 Snowflake userId{};///< The user's Id.
56 };
57
58 /// \brief For updating the bot's current voice state.
59 struct DiscordCoreAPI_Dll ModifyCurrentUserVoiceStateData {
60 std::string requestToSpeakTimestamp{};///< ISO8601 timeStamp.
61 Snowflake channelId{};///< The id of the Channel the user is currently in.
62 Snowflake guildId{};///< The Guild within which to update the bot's voice state.
63 bool suppress{};///< Toggles the user's suppress state.
64 };
65
66 /// \brief For modifying a User's voice state.
67 struct DiscordCoreAPI_Dll ModifyUserVoiceStateData {
68 Snowflake channelId{};///< The id of the Channel the user is currently in.
69 Snowflake guildId{};///< The Guild within which you would like to modify their voice state.
70 Snowflake userId{};///< The user for which you would like to modify the voice state of.
71 bool suppress{};///< Toggles the user's suppress state.
72 };
73
74 /// \brief For getting User responseData from the library's cache or the Discord server.
75 struct DiscordCoreAPI_Dll GetUserData {
76 Snowflake userId{};///< The id of the desired User.
77 };
78
79 /// \brief For modifying the Bot's User responseData.
80 struct DiscordCoreAPI_Dll ModifyCurrentUserData {
81 std::string userName{};///< User's userName, if changed may cause the user's discriminator to be randomized.
82 std::string avatar{};///< If passed, modifies the user's avatar.
83 };
84
85 /// \brief A single User.
86 class DiscordCoreAPI_Dll User : public UserData {
87 public:
88 PremiumType premiumType{};///< The type of Nitro subscription on a user ' s account.
89 int32_t accentColor{};///< The user 's banner color encoded as an integer representation of hexadecimal color code.
90 std::string locale{};///< The user' s chosen language option.
91 std::string email{};///< The user's email.
92 IconHash banner{};///< The user's banner hash.
93
94 User() noexcept = default;
95
96 User& operator=(UserData&& other) noexcept;
97
98 User(UserData&&) noexcept;
99
100 User& operator=(const UserData& other) noexcept;
101
102 User(const UserData&) noexcept;
103
104 User(simdjson::ondemand::value jsonObjectData);
105
106 virtual ~User() noexcept = default;
107 };
108
109 class DiscordCoreAPI_Dll UserVector {
110 public:
111 UserVector() noexcept = default;
112
113 operator std::vector<User>();
114
115 UserVector(simdjson::ondemand::value jsonObjectData);
116
117 virtual ~UserVector() noexcept = default;
118
119 protected:
120 std::vector<User> users{};
121 };
122
123 /// \brief A type of User, to represent the Bot and some of its associated endpoints.
124 class DiscordCoreAPI_Dll BotUser : public User {
125 public:
126 friend class DiscordCoreClient;
127
128 BotUser& operator=(const BotUser& other) noexcept = default;
129
130 BotUser(const BotUser& other) noexcept = default;
131
132 BotUser(UserData dataPackage, DiscordCoreInternal::BaseSocketAgent* pBaseBaseSocketAgentNew);
133
134 /// \brief Updates the bot's current voice-status. Joins/leaves a Channel, and/or self deafens/mutes.
135 void updateVoiceStatus(UpdateVoiceStateData& datdataPackageaPackage);
136
137 /// \brief Updates the bot's current activity status, to be viewed by others in the same server as the bot.
138 void updatePresence(UpdatePresenceData& dataPackage);
139
140 protected:
141 BotUser() noexcept = default;
142
143 DiscordCoreInternal::BaseSocketAgent* baseSocketAgent{ nullptr };
144 };
145 /**@}*/
146
147 /**
148 * \addtogroup main_endpoints
149 * @{
150 */
151 /// \brief An interface class for the User related Discord endpoints.
152 class DiscordCoreAPI_Dll Users {
153 public:
154 friend class DiscordCoreInternal::WebSocketClient;
155 friend class DiscordCoreInternal::BaseSocketAgent;
156 friend class DiscordCoreClient;
157 friend class UserData;
158 friend class Guild;
159
160 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManagerNew);
161
162 /// \brief Adds a chosen recipient to a group DM.
163 /// \param dataPackage An AddRecipientToGroupDMData structure.
164 /// \returns A CoRoutine containing void.
165 static CoRoutine<void> addRecipientToGroupDMAsync(AddRecipientToGroupDMData dataPackage);
166
167 /// \brief Removes a chosen recipient from a group DM.
168 /// \param dataPackage A RemoveRecipientFromGroupDMData structure.
169 /// \returns A CoRoutine containing void.
170 static CoRoutine<void> removeRecipientFromGroupDMAsync(RemoveRecipientFromGroupDMData dataPackage);
171
172 /// \brief Sets the bot's current voice state.
173 /// \param dataPackage A ModifyCurrentUserVoiceStateData structure.
174 /// \returns A CoRoutine containing void.
175 static CoRoutine<void> modifyCurrentUserVoiceStateAsync(ModifyCurrentUserVoiceStateData dataPackage);
176
177 /// \brief Sets another user's current voice state.
178 /// \param dataPackage A ModifyUserVoiceStateData structure.
179 /// \returns A CoRoutine containing void.
180 static CoRoutine<void> modifyUserVoiceStateAsync(ModifyUserVoiceStateData dataPackage);
181
182 /// \brief Collects the Bot's current User responseData.
183 /// \returns A CoRoutine containing a User.
184 static CoRoutine<User> getCurrentUserAsync();
185
186 /// \brief Collects a given User from the library's cache.
187 /// \param dataPackage A GetUserData structure.
188 /// \returns A CoRoutine containing a User.
189 static UserData getCachedUser(GetUserData dataPackage);
190
191 /// \brief Collects a given User from the Discord servers.
192 /// \param dataPackage A GetUserData structure.
193 /// \returns A CoRoutine containing a User.
194 static CoRoutine<User> getUserAsync(GetUserData dataPackage);
195
196 /// \brief Modifies the Bot's User responseData.
197 /// \param dataPackage A ModifyCurrentUserData structure.
198 /// \returns A CoRoutine containing a User.
199 static CoRoutine<User> modifyCurrentUserAsync(ModifyCurrentUserData dataPackage);
200
201 /// \brief Collects the User's Connections.
202 /// \returns A CoRoutine containing a vector<ConnectionData>.
203 static CoRoutine<std::vector<ConnectionData>> getUserConnectionsAsync();
204
205 /// \brief Collects the Application responseData associated with the current Bot.
206 /// \returns A CoRoutine containing an ApplicationData.
207 static CoRoutine<ApplicationData> getCurrentUserApplicationInfoAsync();
208
209 /// \brief Collects the Authorization info associated with the current Bot.
210 /// \returns A CoRoutine containing an AuthorizationInfoData.
211 static CoRoutine<AuthorizationInfoData> getCurrentUserAuthorizationInfoAsync();
212
213 static void insertUser(UserData user);
214
215 static bool doWeCacheUsers();
216
217 protected:
218 static DiscordCoreInternal::HttpsClient* httpsClient;
219 static ObjectCache<UserData> cache;
220 static bool doWeCacheUsersBool;
221 };
222 /**@}*/
223
224}// namespace DiscordCoreAPI
PremiumType
Premium types denote the level of premium a user has.
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 User.
For updating the current voice state.
A discord Guild. Used to connect to/disconnect from voice.
For adding a user to a group DM.
For removing a User from a group DM.
For updating the bot's current voice state.
For modifying a User's voice state.
For getting User responseData from the library's cache or the Discord server.
For modifying the Bot's User responseData.
A single User.
A type of User, to represent the Bot and some of its associated endpoints.
An interface class for the User related Discord endpoints.
For updating a User's presence.
Definition: Utilities.hpp:894