DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
WebHookEntities.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/// WebHookEntities.hpp - the header file for web_hook_data relate stuff.
27/// Dec 1, 2021
28/// https://discordcoreapi.com
29/// \file WebHookEntities.hpp
30#pragma once
31
34
35namespace discord_core_api {
36
37 /**
38 * \addtogroup foundation_entities
39 * @{
40 */
41
42 /// @brief For creating a new web_hook_data.
44 snowflake channelId{};///< The channel_data within which to create the web_hook_data.
45 jsonifier::string avatar{};///< Image for the default webhook avatar.
46 jsonifier::string name{};///< Name of the webhook(1 - 80 characters).
47 };
48
49 /// @brief For executing a web_hook.
50 class DiscordCoreAPI_Dll execute_web_hook_data {
51 public:
52 template<typename value_type> friend struct jsonifier::core;
53 friend class create_ephemeral_follow_up_message_data;
54 friend class create_follow_up_message_data;
55 friend class edit_follow_up_message_data;
56 friend class interactions;
57 friend class web_hooks;
58
59 snowflake threadId{};///< Send a message to the specified thread within a webhook's channel_data. the thread will automatically be unarchived.
60 bool wait{};///< Waits for server confirmation of message send before response, and returns the created message body.
61
62 execute_web_hook_data() = default;
63
64 execute_web_hook_data(const web_hook_data& dataNew);
65
66 /// @brief Adds a button to the response message_data.
67 /// @param disabled whether the button is active or not.
68 /// @param customIdNew a custom id to give for identifying the button.
69 /// @param buttonLabel a visible label for the button.
70 /// @param buttonStyle the style of the button.
71 /// @param emojiName an emoji name, if desired.
72 /// @param emojiId an emoji id, if desired.
73 /// @param url a url, if applicable.
74 /// @return respond_to_input_event_data& a reference to this data structure.
75 execute_web_hook_data& addButton(bool disabled, jsonifier::string_view customIdNew, jsonifier::string_view buttonLabel, button_style buttonStyle,
76 jsonifier::string_view emojiName = "", snowflake emojiId = snowflake{}, jsonifier::string_view url = "");
77
78 /// @brief Adds a select-menu to the response message_data.
79 /// @param disabled whether the select-menu is active or not.
80 /// @param customIdNew a custom id to give for identifying the select-menu.
81 /// @param options a vector of select-menu-options to offer.
82 /// @param placeholder custom placeholder text if nothing is selected, max 100 characters.
83 /// @param maxValues maximum number of selections that are possible.
84 /// @param minValues minimum required number of selections that are required.
85 /// @param type the type of select-menu that this is.
86 /// @param channelTypes types of channels that can be accepted if this is of the type channel_type.
87 /// @return respond_to_input_event_data& a reference to this data structure.
88 execute_web_hook_data& addSelectMenu(bool disabled, jsonifier::string_view customIdNew, const jsonifier::vector<select_option_data>& options,
89 jsonifier::string_view placeholder, int32_t maxValues, int32_t minValues, select_menu_type type,
90 const jsonifier::vector<channel_type>& channelTypes = jsonifier::vector<channel_type>{});
91
92 /// @brief Adds a modal to the response message_data.
93 /// @param topTitleNew a title for the modal.
94 /// @param topCustomIdNew a custom id to give for the modal.
95 /// @param titleNew a title for the modal's individual input.
96 /// @param customIdNew a custom id to give for the modal's individual input.
97 /// @param required is it a required response?
98 /// @param minLength minimum length.
99 /// @param maxLength maximum length.
100 /// @param inputStyle the input style.
101 /// @param label a label for the modal.
102 /// @param placeholder a placeholder for the modal.
103 /// @return respond_to_input_event_data& a reference to this data structure.
104 execute_web_hook_data& addModal(jsonifier::string_view topTitleNew, jsonifier::string_view topCustomIdNew, jsonifier::string_view titleNew,
105 jsonifier::string_view customIdNew, bool required, int32_t minLength, int32_t maxLength, text_input_style inputStyle, jsonifier::string_view label = "",
106 jsonifier::string_view placeholder = "");
107
108 /// @brief Adds a file to the current collection of files for this message response.
109 /// @param theFile the file to be added.
110 /// @return message_response_base& a reference to this data structure.
111 execute_web_hook_data& addFile(const file& theFile);
112
113 /// @brief For setting the allowable mentions in a response.
114 /// @param dataPackage an allowed_mentions_data structure.
115 /// @return message_response_base& a reference to this data structure.
116 execute_web_hook_data& addAllowedMentions(const allowed_mentions_data dataPackage);
117
118 /// @brief For setting the components in a response.
119 /// @param dataPackage an action_row_data structure.
120 /// @return message_response_base& a reference to this data structure.
121 execute_web_hook_data& addComponentRow(const action_row_data dataPackage);
122
123 /// @brief For setting the embeds in a response.
124 /// @param dataPackage an embed_data structure.
125 /// @return message_response_base& a reference to this data structure.
126 execute_web_hook_data& addMessageEmbed(const embed_data dataPackage);
127
128 /// @brief For setting the content in a response.
129 /// @param dataPackage a string, containing the content.
130 /// @return message_response_base& a reference to this data structure.
131 execute_web_hook_data& addContent(jsonifier::string_view dataPackage);
132
133 /// @brief For setting the tts status of a response.
134 /// @param enabledTTs a bool.
135 /// @return message_response_base& a reference to this data structure.
136 execute_web_hook_data& setTTSStatus(bool enabledTTs);
137
138 void generateExcludedKeys();
139
140 unordered_set<jsonifier::string> jsonifierExcludedKeys{};
141
142 protected:
143 jsonifier::vector<attachment_data> attachments{};///< Array of partial attachment objects attachment objects with filename and description.
144 jsonifier::vector<action_row_data> components{};///< Array of message component the components to include with the message.
145 allowed_mentions_data allowedMentions{};///< Allowed mention object.
146 jsonifier::vector<embed_data> embeds{};///< Array of up to 10 embed objects.
147 jsonifier::vector<file> files{};///< File contents the contents of the file being sent.
148 jsonifier::string webhookToken{};///< The web_hook_data token you would like to execute.
149 jsonifier::string avatarUrl{};///< Override the default avatar of the webhook.
150 jsonifier::string userName{};///< Override the default username of the webhook.
151 jsonifier::string customId{};///< custom id for the modal.
152 snowflake webHookId{};///< The web_hook_data you would like to execute.
153 jsonifier::string content{};///< The message contents (up to 2000 characters) one of content, file, embeds.
154 jsonifier::string title{};///< Title for the modal.
155 uint64_t flags{};///< Flags combined as a bitfield.
156 bool tts{};///< True if this is a tts message.
157 };
158
159 /// @brief For editing a web_hook message_data.
160 class DiscordCoreAPI_Dll edit_web_hook_data : public execute_web_hook_data {
161 public:
162 template<typename value_type> friend struct jsonifier::core;
163 friend class edit_interaction_response_data;
164 friend class edit_follow_up_message_data;
165 friend class interactions;
166 friend class web_hooks;
167
168 snowflake messageId{};///< The message snowflake to collect.
169 snowflake threadId{};///< Send a message to the specified thread within a webhook's channel_data. the thread will automatically be unarchived.
170 bool wait{};///< Waits for server confirmation of message send before response, and returns the created message body.
171
172 execute_web_hook_data& setTTSStatus(bool) = delete;
173
174 edit_web_hook_data() = default;
175
176 edit_web_hook_data(const web_hook_data& dataNew);
177 };
178
179 /// @brief For collecting a list of web_hooks from a chosen channel_data.
181 snowflake channelId{};///< The channel_data from which to collect the web_hooks.
182 };
183
184 /// @brief For collecting a list of web_hooks from a chosen guild.
186 snowflake guildId{};///< The guild from which to collect the web_hooks.
187 };
188
189 /// @brief Collects a single web_hook_data.
191 snowflake webHookId{};///< snowflake of the desired web_hook_data to collect.
192 };
193
194 /// @brief Collects a single web_hook_data, using the token and snowflake.
196 jsonifier::string webhookToken{};///< Token of the desired web_hook_data.
197 snowflake webHookId{};///< snowflake of the desired web_hook_data.
198 };
199
200 /// @brief For modifying a web_hook.
202 snowflake channelId{};///< The new channel_data id this webhook should be moved to.
203 snowflake webHookId{};///< The web_hook_data to be modified.
204 jsonifier::string avatar{};///< Image responseData for the default webhook avatar.
205 jsonifier::string name{};///< The default name of the webhook.
206 };
207
208 /// @brief For modifying a web_hook.
210 jsonifier::string webhookToken{};///< Token of the desired web_hook_data.
211 snowflake channelId{};///< The new channel_data id this webhook should be moved to.
212 snowflake webHookId{};///< The web_hook_data to be modified.
213 jsonifier::string avatar{};///< Image responseData for the default webhook avatar.
214 jsonifier::string name{};///< The default name of the webhook.
215 };
216
217 /// @brief For deleting a web_hook.
219 snowflake webHookId{};///< The desired web_hook_data to delete.
220 };
221
222 /// @brief For deleting a web_hook, using its token.
224 jsonifier::string webhookToken{};///< Token of the desired web_hook_data.
225 snowflake webHookId{};///< The desired web_hook_data to delete.
226 };
227
228 /// @brief For getting a web_hook message_data.
230 jsonifier::string webhookToken{};///< The web_hook_data token you would like to collect.
231 snowflake webHookId{};///< The web_hook_data you would like to collect.
232 snowflake messageId{};///< The message snowflake to collect.
233 snowflake threadId{};///< The thread that the message is in.
234 };
235
236 /// @brief For deleting a web_hook message_data.
238 jsonifier::string webhookToken{};///< The web_hook_data token you would like to collect.
239 snowflake webHookId{};///< The web_hook_data you would like to collect.
240 snowflake messageId{};///< The message snowflake to collect.
241 snowflake threadId{};///< Send a message to the specified thread within a webhook's channel_data. the thread will automatically be unarchived.
242 };
243
244 /**@}*/
245
246 /**
247 * \addtogroup main_endpoints
248 * @{
249 */
250 /// @brief An interface class for the web_hook_data related discord endpoints;
251 class DiscordCoreAPI_Dll web_hooks {
252 public:
253 static void initialize(discord_core_internal::https_client*);
254
255 /// @brief Creates a new web_hook_data.
256 /// @param dataPackage a get_message_data structure.
257 /// @return a co_routine containing a web_hook.
258 static co_routine<web_hook_data> createWebHookAsync(create_web_hook_data dataPackage);
259
260 /// @brief Collects a list of web_hooks from a chosen channel_data.
261 /// @param dataPackage a get_channel_web_hooks_data structure.
262 /// @return a co_routine containing a jsonifier::vector<web_hook_data>.
263 static co_routine<jsonifier::vector<web_hook_data>> getChannelWebHooksAsync(get_channel_web_hooks_data dataPackage);
264
265 /// @brief Collects a list of web_hooks from a chosen guild.
266 /// @param dataPackage a get_guild_web_hooks_data structure.
267 /// @return a co_routine containing a jsonifier::vector<web_hook_data>.
268 static co_routine<jsonifier::vector<web_hook_data>> getGuildWebHooksAsync(get_guild_web_hooks_data dataPackage);
269
270 /// @brief Collects a single web_hook_data.
271 /// @param dataPackage a get_web_hook_data structure.
272 /// @return a co_routine containing a web_hook.
273 static co_routine<web_hook_data> getWebHookAsync(get_web_hook_data dataPackage);
274
275 /// @brief Collects a single web_hook_data, using the token.
276 /// @param dataPackage a get_web_hook_with_token_data structure.
277 /// @return a co_routine containing a web_hook.
278 static co_routine<web_hook_data> getWebHookWithTokenAsync(get_web_hook_with_token_data dataPackage);
279
280 /// @brief Modifies a single web_hook_data.
281 /// @param dataPackage a modify_web_hook_data structure.
282 /// @return a co_routine containing a web_hook.
283 static co_routine<web_hook_data> modifyWebHookAsync(modify_web_hook_data dataPackage);
284
285 /// @brief Modifies a single web_hook_data, using its token.
286 /// @param dataPackage a modify_web_hook_with_token_data structure.
287 /// @return a co_routine containing a web_hook.
288 static co_routine<web_hook_data> modifyWebHookWithTokenAsync(modify_web_hook_with_token_data dataPackage);
289
290 /// @brief Deletes a single web_hook_data.
291 /// @param dataPackage a delete_web_hook_data structure.
292 /// @return a co_routine containing void.
293 static co_routine<void> deleteWebHookAsync(delete_web_hook_data dataPackage);
294
295 /// @brief Deletes a single web_hook_data, using its token.
296 /// @param dataPackage a delete_web_hook_with_token_data structure.
297 /// @return a co_routine containing void.
298 static co_routine<void> deleteWebHookWithTokenAsync(delete_web_hook_with_token_data dataPackage);
299
300 /// @brief Executes a single web_hook_data.
301 /// @param dataPackage an execute_web_hook_data structure.
302 /// @return a co_routine containing a message.
303 static co_routine<message_data> executeWebHookAsync(execute_web_hook_data dataPackage);
304
305 /// @brief Collects a web_hook message_data.
306 /// @param dataPackage an get_web_hook_message_data structure.
307 /// @return a co_routine containing a message.
308 static co_routine<message_data> getWebHookMessageAsync(get_web_hook_message_data dataPackage);
309
310 /// @brief Edits a web_hook message_data.
311 /// @param dataPackage an edit_web_hook_data_message_data structure.
312 /// @return a co_routine containing a message.
313 static co_routine<message_data> editWebHookMessageAsync(edit_web_hook_data dataPackage);
314
315 /// @brief Deletes a web_hook message_data.
316 /// @param dataPackage an delete_web_hook_message_data structure.
317 /// @return a co_routine containing a message.
318 static co_routine<void> deleteWebHookMessageAsync(delete_web_hook_message_data dataPackage);
319
320 protected:
321 static discord_core_internal::https_client* httpsClient;
322 };
323 /**@}*/
324
325}
For editing a web_hook message_data.
An interface class for the web_hook_data related discord endpoints;.
The main namespace for the forward-facing interfaces.
For creating a new web_hook_data.
jsonifier::string name
Name of the webhook(1 - 80 characters).
snowflake channelId
The channel_data within which to create the web_hook_data.
jsonifier::string avatar
Image for the default webhook avatar.
snowflake webHookId
The desired web_hook_data to delete.
For deleting a web_hook message_data.
snowflake threadId
Send a message to the specified thread within a webhook's channel_data. the thread will automatically...
snowflake webHookId
The web_hook_data you would like to collect.
snowflake messageId
The message snowflake to collect.
jsonifier::string webhookToken
The web_hook_data token you would like to collect.
For deleting a web_hook, using its token.
snowflake webHookId
The desired web_hook_data to delete.
jsonifier::string webhookToken
Token of the desired web_hook_data.
For collecting a list of web_hooks from a chosen channel_data.
snowflake channelId
The channel_data from which to collect the web_hooks.
For collecting a list of web_hooks from a chosen guild.
snowflake guildId
The guild from which to collect the web_hooks.
Collects a single web_hook_data.
snowflake webHookId
snowflake of the desired web_hook_data to collect.
For getting a web_hook message_data.
jsonifier::string webhookToken
The web_hook_data token you would like to collect.
snowflake webHookId
The web_hook_data you would like to collect.
snowflake messageId
The message snowflake to collect.
snowflake threadId
The thread that the message is in.
Collects a single web_hook_data, using the token and snowflake.
snowflake webHookId
snowflake of the desired web_hook_data.
jsonifier::string webhookToken
Token of the desired web_hook_data.
jsonifier::string avatar
Image responseData for the default webhook avatar.
snowflake channelId
The new channel_data id this webhook should be moved to.
snowflake webHookId
The web_hook_data to be modified.
jsonifier::string name
The default name of the webhook.
snowflake channelId
The new channel_data id this webhook should be moved to.
jsonifier::string webhookToken
Token of the desired web_hook_data.
jsonifier::string avatar
Image responseData for the default webhook avatar.
jsonifier::string name
The default name of the webhook.
snowflake webHookId
The web_hook_data to be modified.