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 guild_member_data 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 discord_core_api {
39
40 /**
41 * \addtogroup foundation_entities
42 * @{
43 */
44
45 /// @brief For getting a guild_member, from the library's cache or discord server.
47 snowflake guildMemberId{};///< The user id of the desired guild_member_data.
48 snowflake guildId{};///< The id of the guild from which you would like to acquire a member.
49 };
50
51 /// @brief For listing the guild_members of a chosen guild.
53 snowflake guildId{};///< Guild from which to list the guild_members.
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 guild_members within a chosen guild.
60 snowflake guildId{};///< Guild within which to search for the guild_members.
61 jsonifier::string query{};///< Query jsonifier::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 guild_member_data to a chosen guild.
67 jsonifier::vector<snowflake> roles{};///< Array of role_data ids the member is assigned.
68 jsonifier::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 guild_member_data to.
70 snowflake userId{};///< The user_data id of the user you wish to add.
71 jsonifier::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 guild_member_data's values.
78 jsonifier::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 jsonifier::string nick{};///< A new nickname for the current user.
81 };
82
83 /// @brief For modifying a guild_member's values.
85 jsonifier::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 role_data id's to be applied to them.
87 snowflake newVoiceChannelId{};///< The new voice channel_data to move them into.
88 snowflake currentChannelId{};///< The current voice channel_data, 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 jsonifier::string reason{};///< Reason for modifying this guild_member_data.
92 jsonifier::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 guild_member from a chosen guild.
99 snowflake guildMemberId{};///< snowflake of the chosen guild_member_data to kick.
100 jsonifier::string reason{};///< Reason for kicking the guild_member_data.
101 snowflake guildId{};///< Guild from which to kick the chosen guild_member_data.
102 };
103
104 /// @brief For timing out a guild_member.
106 timeout_durations numOfMinutesToTimeoutFor{};///< The number of minutes to time-out the guild_member_data for.
107 snowflake guildMemberId{};///< The id of the guild_member_data to be timed-out.
108 jsonifier::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 guild_member_data related discord endpoints.
120 class DiscordCoreAPI_Dll guild_members {
121 public:
123 friend class discord_core_client;
124 friend class guild_member_data;
125 friend class guild_data;
126 friend class guild;
127
128 static void initialize(discord_core_internal::https_client*, config_manager* configManagerNew);
129
130 /// @brief Collects a guild_member from the discord servers.
131 /// @param dataPackage a get_guild_member_data structure.
132 /// @return a co_routine containing a guild_member.
133 static co_routine<guild_member_data> getGuildMemberAsync(const get_guild_member_data dataPackage);
134
135 /// @brief Collects a guild_member from the library's cache.
136 /// @param dataPackage a get_guild_member_data structure.
137 /// @return a co_routine containing a guild_member.
138 static guild_member_cache_data getCachedGuildMember(const get_guild_member_data dataPackage);
139
140 /// @brief Lists all of the guild_members of a chosen guild.
141 /// @param dataPackage a list_guild_members_data structure.
142 /// @return a co_routine containing a vector<guild_members>.
143 static co_routine<jsonifier::vector<guild_member_data>> listGuildMembersAsync(const list_guild_members_data dataPackage);
144
145 /// @brief Searches for a list of guild_members of a chosen guild.
146 /// @param dataPackage a search_guild_members_data structure.
147 /// @return a co_routine containing a vector<guild_members>.
148 static co_routine<jsonifier::vector<guild_member_data>> searchGuildMembersAsync(const search_guild_members_data dataPackage);
149
150 /// @brief Adds a guild_member to a chosen guild.
151 /// @param dataPackage an add_guild_member_data structure.
152 /// @return a co_routine containing a vector<guild_members>.
153 static co_routine<guild_member_data> addGuildMemberAsync(const add_guild_member_data dataPackage);
154
155 /// @brief Modifies a guild_member's properties.
156 /// @param dataPackage a modify_guild_member_data structure.
157 /// @return a co_routine containing a guild_member.
158 static co_routine<guild_member_data> modifyGuildMemberAsync(const modify_guild_member_data dataPackage);
159
160 /// @brief Modifies the current guild_member_data's properties.
161 /// @param dataPackage a modify_current_guild_member_data structure.
162 /// @return a co_routine containing a guild_member.
163 static co_routine<guild_member_data> modifyCurrentGuildMemberAsync(const modify_current_guild_member_data dataPackage);
164
165 /// @brief Removes a chosen guild_member_data from a chosen guild.
166 /// @param dataPackage a remove_guild_member_data structure.
167 /// @return a co_routine containing void.
168 static co_routine<void> removeGuildMemberAsync(const remove_guild_member_data dataPackage);
169
170 /// @brief Times-out a chosen guild_member_data from a chosen guild.
171 /// @param dataPackage a timeout_guild_member_data structure.
172 /// @return a co_routine containing guild_member_data.
173 static co_routine<guild_member_data> timeoutGuildMemberAsync(const timeout_guild_member_data dataPackage);
174
175 template<typename voice_state_type> inline static void insertVoiceState(voice_state_type&& voiceState) {
176 if (doWeCacheVoiceStatesBool) {
177 if (voiceState.userId == 0) {
178 throw dca_exception{ "Sorry, but there was no id set for that voice state." };
179 }
180 vsCache.emplace(std::forward<voice_state_type>(voiceState));
181 }
182 }
183
184 template<typename guild_member_type> inline static void insertGuildMember(guild_member_type&& guildMember) {
185 if (doWeCacheGuildMembersBool) {
186 if (guildMember.guildId == 0 || guildMember.user.id == 0) {
187 throw dca_exception{ "Sorry, but there was no id set for that guildmember." };
188 }
189 cache.emplace(static_cast<guild_member_cache_data>(std::forward<guild_member_type>(guildMember)));
190 }
191 }
192
193 /// @brief Collect a given guild_member's voice state data.
194 /// @param voiceState A two-id-key representing their user-id and guild-id.
195 /// @return voice_state_data_light The guild_member's voice_state_data.
196 static voice_state_data_light getVoiceStateData(const two_id_key& voiceState);
197
198 static void removeGuildMember(const two_id_key& guildMemberId);
199
200 static void removeVoiceState(const two_id_key& voiceState);
201
202 static bool doWeCacheGuildMembers();
203
204 static bool doWeCacheVoiceStates();
205
206 protected:
207 static discord_core_internal::https_client* httpsClient;
210 static bool doWeCacheGuildMembersBool;
211 static bool doWeCacheVoiceStatesBool;
212 };
213 /**@}*/
214};
A co_routine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:83
discord_core_client - the main class for this library.
A websocket client, for communication via a tcp-connection.
A discord guild. used to connect to/disconnect from voice.
Data structure representing a single guild_member_data.
Data structure representing a single guild_member_data.
An interface class for the guild_member_data related discord endpoints.
A template class representing an object cache.
Definition: ObjectCache.hpp:40
An interface class for the role_data related discord endpoints.
A class representing a snowflake identifier with various operations.
Definition: Base.hpp:680
timeout_durations
Timeout durations for the timeout command.
The main namespace for the forward-facing interfaces.
For adding a new guild_member_data to a chosen guild.
snowflake userId
The user_data id of the user you wish to add.
jsonifier::string nick
Value to set users nickname to.
bool mute
Whether the user is muted in voice channels.
bool deaf
Whether the user is deafened in voice channels.
jsonifier::string accessToken
An oauth2 access token granted with the guilds.join to the bot's application for the user you want to...
snowflake guildId
The guild to add the new guild_member_data to.
An exception class derived from std::runtime_error for dca-related exceptions.
Definition: Base.hpp:820
For getting a guild_member, from the library's cache or discord server.
snowflake guildMemberId
The user id of the desired guild_member_data.
snowflake guildId
The id of the guild from which you would like to acquire a member.
For listing the guild_members of a chosen guild.
snowflake after
The highest user id in the previous page.
int32_t limit
Max number of members to return (1 - 1000).
snowflake guildId
Guild from which to list the guild_members.
For modifying the current guild_member_data's values.
jsonifier::string nick
A new nickname for the current user.
jsonifier::string reason
A reason for modifying the current user's values.
snowflake guildId
The guild within which to modify the current user's values.
For modifying a guild_member's values.
snowflake guildId
The id of the guild for which you would like to modify a member.
jsonifier::string communicationDisabledUntil
When the user's timeout will expire and the user will be able to communicate in the guild again.
jsonifier::vector< snowflake > roleIds
A collection of role_data id's to be applied to them.
bool deaf
Whether or not to deafen them, in voice.
bool mute
Whether or not to mute them in voice.
jsonifier::string reason
Reason for modifying this guild_member_data.
jsonifier::string nick
Their new display/nick name.
snowflake currentChannelId
The current voice channel_data, if applicaple.
snowflake newVoiceChannelId
The new voice channel_data to move them into.
snowflake guildMemberId
The user id of the desired guild memeber.
For removing a guild_member from a chosen guild.
snowflake guildMemberId
snowflake of the chosen guild_member_data to kick.
snowflake guildId
Guild from which to kick the chosen guild_member_data.
jsonifier::string reason
Reason for kicking the guild_member_data.
For searching for one or more guild_members within a chosen guild.
int32_t limit
Max number of members to return (1 - 1000).
snowflake guildId
Guild within which to search for the guild_members.
jsonifier::string query
Query jsonifier::string to match username(s) and nickname(s) against.
jsonifier::string reason
Reason for timing them out.
snowflake guildMemberId
The id of the guild_member_data to be timed-out.
snowflake guildId
The id of the guild from which you would like to acquire a member.
timeout_durations numOfMinutesToTimeoutFor
The number of minutes to time-out the guild_member_data for.