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 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/// UserEntities.hpp - Header for user_data related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file UserEntities.hpp
30#pragma once
31
35
36namespace discord_core_api {
37
38 /**
39 * \addtogroup foundation_entities
40 * @{
41 */
42
43 /// @brief For adding a user to a group dm.
45 snowflake channelId{};///< The channel_data snowflake of the dm.
46 jsonifier::string token{};///< The user's access token.
47 jsonifier::string nick{};///< The user's nickname.
48 snowflake userId{};///< The user's snowflake.
49 };
50
51 /// @brief For removing a user from a group dm.
53 snowflake channelId{};///< The channel_data snowflake of the dm.
54 snowflake userId{};///< The user's snowflake.
55 };
56
57 /// @brief For updating the bot's current voice state.
59 jsonifier::string requestToSpeakTimestamp{};///< Iso8601 timeStamp.
60 snowflake channelId{};///< The id of the channel_data the user is currently in.
61 snowflake guildId{};///< The guild within which to update the bot's voice state.
62 bool suppress{};///< Toggles the user's suppress state.
63 };
64
65 /// @brief For modifying a user's voice state.
67 snowflake channelId{};///< The id of the channel_data the user is currently in.
68 snowflake guildId{};///< The guild within which you would like to modify their voice state.
69 snowflake userId{};///< The user for which you would like to modify the voice state of.
70 bool suppress{};///< Toggles the user's suppress state.
71 };
72
73 /// @brief For getting user_data responseData from the library's cache or the discord server.
75 snowflake userId{};///< The id of the desired user_data.
76 };
77
78 /// @brief For modifying the bot's user_data responseData.
80 jsonifier::string userName{};///< User_data's username, if changed may cause the user's discriminator to be randomized.
81 jsonifier::string avatar{};///< If passed, modifies the user's avatar.
82 };
83
84 /**@}*/
85
86 /**
87 * \addtogroup main_endpoints
88 * @{
89 */
90 /// @brief An interface class for the user_data related discord endpoints.
91 class DiscordCoreAPI_Dll users {
92 public:
93 friend class discord_core_internal::websocket_client;
94 friend class discord_core_internal::base_socket_agent;
95 friend class discord_core_client;
96 friend class user_data;
97 friend class guild;
98
99 static void initialize(discord_core_internal::https_client*, config_manager* configManagerNew);
100
101 /// @brief Adds a chosen recipient to a group dm.
102 /// @param dataPackage an add_recipient_to_group_dmdata structure.
103 /// @return A co_routine containing void.
104 static co_routine<void> addRecipientToGroupDMAsync(add_recipient_to_group_dmdata dataPackage);
105
106 /// @brief Removes a chosen recipient from a group dm.
107 /// @param dataPackage a remove_recipient_from_group_dmdata structure.
108 /// @return A co_routine containing void.
109 static co_routine<void> removeRecipientFromGroupDMAsync(remove_recipient_from_group_dmdata dataPackage);
110
111 /// @brief Sets the bot's current voice state.
112 /// @param dataPackage a modify_current_user_voice_state_data structure.
113 /// @return A co_routine containing void.
114 static co_routine<void> modifyCurrentUserVoiceStateAsync(modify_current_user_voice_state_data dataPackage);
115
116 /// @brief Sets another user's current voice state.
117 /// @param dataPackage a modify_user_voice_state_data structure.
118 /// @return A co_routine containing void.
119 static co_routine<void> modifyUserVoiceStateAsync(modify_user_voice_state_data dataPackage);
120
121 /// @brief Collects the bot's current user_data responseData.
122 /// @return A co_routine containing a user.
123 static co_routine<user_data> getCurrentUserAsync();
124
125 /// @brief Collects a given user from the library's cache.
126 /// @param dataPackage a get_user_data structure.
127 /// @return A co_routine containing a user.
128 static user_cache_data getCachedUser(get_user_data dataPackage);
129
130 /// @brief Collects a given user from the discord servers.
131 /// @param dataPackage a get_user_data structure.
132 /// @return A co_routine containing a user.
133 static co_routine<user_data> getUserAsync(get_user_data dataPackage);
134
135 /// @brief Modifies the bot's user_data responseData.
136 /// @param dataPackage a modify_current_user_data structure.
137 /// @return A co_routine containing a user.
138 static co_routine<user_data> modifyCurrentUserAsync(modify_current_user_data dataPackage);
139
140 /// @brief Collects the user_data's connections.
141 /// @return A co_routine containing a vector<connection_data>.
142 static co_routine<jsonifier::vector<connection_data>> getUserConnectionsAsync();
143
144 /// @brief Collects the application responseData associated with the current bot.
145 /// @return A co_routine containing an application_data.
146 static co_routine<application_data> getCurrentUserApplicationInfoAsync();
147
148 /// @brief Collects the authorization info associated with the current bot.
149 /// @return A co_routine containing an authorization_info_data.
150 static co_routine<authorization_info_data> getCurrentUserAuthorizationInfoAsync();
151
152 template<typename user_type> DCA_INLINE static void insertUser(user_type&& user) {
153 if (doWeCacheUsersBool) {
154 if (user.id == 0) {
155 throw dca_exception{ "Sorry, but there was no id set for that user." };
156 }
157 cache.emplace(std::forward<user_type>(user));
158 if (cache.count() % 1000 == 0) {
159 std::cout << "current user count: " << cache.count() << std::endl;
160 }
161 }
162 }
163
164 static bool doWeCacheUsers();
165
166 protected:
167 static discord_core_internal::https_client* httpsClient;
168 static object_cache<user_cache_data> cache;
169 static bool doWeCacheUsersBool;
170 };
171 /**@}*/
172
173}
An interface class for the user_data related discord endpoints.
The main namespace for the forward-facing interfaces.
snowflake channelId
The channel_data snowflake of the dm.
jsonifier::string token
The user's access token.
jsonifier::string nick
The user's nickname.
For getting user_data responseData from the library's cache or the discord server.
snowflake userId
The id of the desired user_data.
For modifying the bot's user_data responseData.
jsonifier::string userName
User_data's username, if changed may cause the user's discriminator to be randomized.
jsonifier::string avatar
If passed, modifies the user's avatar.
For updating the bot's current voice state.
bool suppress
Toggles the user's suppress state.
snowflake guildId
The guild within which to update the bot's voice state.
jsonifier::string requestToSpeakTimestamp
Iso8601 timeStamp.
snowflake channelId
The id of the channel_data the user is currently in.
For modifying a user's voice state.
snowflake guildId
The guild within which you would like to modify their voice state.
snowflake userId
The user for which you would like to modify the voice state of.
bool suppress
Toggles the user's suppress state.
snowflake channelId
The id of the channel_data the user is currently in.
snowflake channelId
The channel_data snowflake of the dm.