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 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/// WebHookEntities.hpp - The header file for WebHook relate stuff.
22/// Dec 1, 2021
23/// https://discordcoreapi.com
24/// \file WebHookEntities.hpp
25
26#pragma once
27
30
31namespace DiscordCoreAPI {
32
33 /**
34 * \addtogroup foundation_entities
35 * @{
36 */
37
38 /// \brief For creating a new WebHook.
39 struct DiscordCoreAPI_Dll CreateWebHookData {
40 Snowflake channelId{};///< The Channel within which to create the WebHook.
41 std::string avatar{};///< Image for the default webhook avatar.
42 std::string name{};///< Name of the webhook(1 - 80 characters).
43 };
44
45 /// \brief For executing a WebHook.
46 class DiscordCoreAPI_Dll ExecuteWebHookData {
47 public:
49 friend class CreateFollowUpMessageData;
50 friend class EditFollowUpMessageData;
51 friend class Interactions;
52 friend class WebHooks;
53
54 Snowflake
55 threadId{};///< Send a message to the specified thread within a webhook's Channel. The thread will automatically be unarchived.
56 bool wait{};///< Waits for server confirmation of message send before response, and returns the created message body.
57
58 ExecuteWebHookData() noexcept = default;
59
61
62 operator Serializer();
63
64 /// \brief Adds a button to the response Message.
65 /// \param disabled Whether the button is active or not.
66 /// \param customIdNew A custom id to give for identifying the button.
67 /// \param buttonLabel A visible label for the button.
68 /// \param buttonStyle The style of the button.
69 /// \param emojiName An emoji name, if desired.
70 /// \param emojiId An emoji id, if desired.
71 /// \param url A url, if applicable.
72 ExecuteWebHookData& addButton(bool disabled, const std::string& customIdNew, const std::string& buttonLabel,
73 ButtonStyle buttonStyle, const std::string& emojiName = "", Snowflake emojiId = Snowflake{}, const std::string& url = "");
74
75 /// \brief Adds a select-menu to the response Message.
76 /// \param disabled Whether the select-menu is active or not.
77 /// \param customIdNew A custom id to give for identifying the select-menu.
78 /// \param options A vector of select-menu-options to offer.
79 /// \param placeholder Custom placeholder text if nothing is selected, max 100 characters.
80 /// \param maxValues Maximum number of selections that are possible.
81 /// \param minValues Minimum required number of selections that are required.
82 /// \param type The type of select-menu that this is.
83 /// \param channelTypes Types of channels that can be accepted if this is of the type ChannelType.
84 /// \returns RespondToInputEventData& A reference to this data structure.
85 ExecuteWebHookData& addSelectMenu(bool disabled, const std::string& customIdNew, std::vector<SelectOptionData> options,
86 const std::string& placeholder, int32_t maxValues, int32_t minValues, SelectMenuType type,
87 std::vector<ChannelType> channelTypes = std::vector<ChannelType>{});
88
89 /// \brief Adds a modal to the response Message.
90 /// \param topTitleNew A title for the modal.
91 /// \param topCustomIdNew A custom id to give for the modal.
92 /// \param titleNew A title for the modal's individual input.
93 /// \param customIdNew A custom id to give for the modal's individual input.
94 /// \param required Is it a required response?
95 /// \param minLength Minimum length.
96 /// \param maxLength Maximum length.
97 /// \param inputStyle The input style.
98 /// \param label A label for the modal.
99 /// \param placeholder A placeholder for the modal.
100 /// \returns RespondToInputEventData& A reference to this data structure.
101 ExecuteWebHookData& addModal(const std::string& topTitleNew, const std::string& topCustomIdNew, const std::string& titleNew,
102 const std::string& customIdNew, bool required, int32_t minLength, int32_t maxLength, TextInputStyle inputStyle,
103 const std::string& label = "", const std::string& placeholder = "");
104
105 /// \brief Adds a file to the current collection of files for this message response.
106 /// \param theFile The file to be added.
107 /// \returns MessageResponseBase& A reference to this data structure.
108 ExecuteWebHookData& addFile(File theFile);
109
110 /// \brief For setting the allowable mentions in a response.
111 /// \param dataPackage An AllowedMentionsData structure.
112 ExecuteWebHookData& addAllowedMentions(AllowedMentionsData dataPackage);
113
114 /// \brief For setting the components in a response.
115 /// \param dataPackage An ActionRowData structure.
116 ExecuteWebHookData& addComponentRow(ActionRowData dataPackage);
117
118 /// \brief For setting the embeds in a response.
119 /// \param dataPackage An EmbedData structure.
120 ExecuteWebHookData& addMessageEmbed(EmbedData dataPackage);
121
122 /// \brief For setting the content in a response.
123 /// \param dataPackage A string, containing the content.
124 ExecuteWebHookData& addContent(const std::string& dataPackage);
125
126 /// \brief For setting the tts status of a response.
127 /// \param enabledTTs A bool.
128 ExecuteWebHookData& setTTSStatus(bool enabledTTs);
129
130 protected:
131 std::vector<AttachmentData> attachments{};///< Array of partial attachment objects attachment objects with filename and description.
132 std::vector<ActionRowData> components{};///< Array of message component the components to include with the message.
133 AllowedMentionsData allowedMentions{};///< Allowed mention object.
134 std::vector<EmbedData> embeds{};///< Array of up to 10 embed objects.
135 std::string webhookToken{};///< The WebHook token you would like to execute.
136 std::vector<File> files{};///< File contents the contents of the file being sent.
137 std::string avatarUrl{};///< Override the default avatar of the webhook.
138 std::string userName{};///< Override the default userName of the webhook.
139 std::string customId{};///< Custom id for the modal.
140 Snowflake webHookId{};///< The WebHook you would like to execute.
141 std::string content{};///< The message contents (up to 2000 characters) one of content, file, embeds.
142 std::string title{};///< Title for the modal.
143 int32_t flags{};///< Flags combined as a bitfield.
144 bool tts{};///< True if this is a TTS message.
145 };
146
147 /// \brief For editing a WebHook Message.
148 class DiscordCoreAPI_Dll EditWebHookData : public ExecuteWebHookData {
149 public:
150 friend class EditInteractionResponseData;
151 friend class EditFollowUpMessageData;
152 friend class Interactions;
153 friend class WebHooks;
154
155 Snowflake messageId{};///< The Message Id to collect.
156 Snowflake
157 threadId{};///< Send a message to the specified thread within a webhook's Channel. The thread will automatically be unarchived.
158 bool wait{};///< Waits for server confirmation of message send before response, and returns the created message body.
159
160 ExecuteWebHookData& setTTSStatus(bool) = delete;
161
162 EditWebHookData() noexcept = default;
163
165
166 operator Serializer();
167 };
168
169 /// \brief For collecting a list of WebHooks from a chosen Channel.
170 struct DiscordCoreAPI_Dll GetChannelWebHooksData {
171 Snowflake channelId{};///< The Channel from which to collect the WebHooks.
172 };
173
174 /// \brief For collecting a list of WebHooks from a chosen Guild.
175 struct DiscordCoreAPI_Dll GetGuildWebHooksData {
176 Snowflake guildId{};///< The Guild from which to collect the WebHooks.
177 };
178
179 /// \brief Collects a single WebHook.
180 struct DiscordCoreAPI_Dll GetWebHookData {
181 Snowflake webHookId{};///< Id of the desired WebHook to collect.
182 };
183
184 /// \brief Collects a single WebHook, using the Token and Id.
185 struct DiscordCoreAPI_Dll GetWebHookWithTokenData {
186 std::string webhookToken{};///< Token of the desired WebHook.
187 Snowflake webHookId{};///< Id of the desired WebHook.
188 };
189
190 /// \brief For modifying a WebHook.
191 struct DiscordCoreAPI_Dll ModifyWebHookData {
192 Snowflake channelId{};///< The new Channel id this webhook should be moved to.
193 Snowflake webHookId{};///< The WebHook to be modified.
194 std::string avatar{};///< Image responseData for the default webhook avatar.
195 std::string name{};///< The default name of the webhook.
196 };
197
198 /// \brief For modifying a WebHook.
199 struct DiscordCoreAPI_Dll ModifyWebHookWithTokenData {
200 std::string webhookToken{};///< Token of the desired WebHook.
201 Snowflake channelId{};///< The new Channel id this webhook should be moved to.
202 Snowflake webHookId{};///< The WebHook to be modified.
203 std::string avatar{};///< Image responseData for the default webhook avatar.
204 std::string name{};///< The default name of the webhook.
205 };
206
207 /// \brief For deleting a WebHook.
208 struct DiscordCoreAPI_Dll DeleteWebHookData {
209 Snowflake webHookId{};///< The desired WebHook to delete.
210 };
211
212 /// \brief For deleting a WebHook, using its Token.
213 struct DiscordCoreAPI_Dll DeleteWebHookWithTokenData {
214 std::string webhookToken{};///< Token of the desired WebHook.
215 Snowflake webHookId{};///< The desired WebHook to delete.
216 };
217
218 /// \brief For getting a WebHook Message.
219 struct DiscordCoreAPI_Dll GetWebHookMessageData {
220 std::string webhookToken{};///< The WebHook token you would like to collect.
221 Snowflake webHookId{};///< The WebHook you would like to collect.
222 Snowflake messageId{};///< The Message Id to collect.
223 Snowflake threadId{};///< The thread that the Message is in.
224 };
225
226 /// \brief For deleting a WebHook Message.
227 struct DiscordCoreAPI_Dll DeleteWebHookMessageData {
228 std::string webhookToken{};///< The WebHook token you would like to collect.
229 Snowflake webHookId{};///< The WebHook you would like to collect.
230 Snowflake messageId{};///< The Message Id to collect.
231 Snowflake
232 threadId{};///< Send a message to the specified thread within a webhook's Channel. The thread will automatically be unarchived.
233 };
234
235 /// \brief A single WebHook.
236 class DiscordCoreAPI_Dll WebHook : public WebHookData {
237 public:
238 WebHook() noexcept = default;
239
240 WebHook(Value jsonData);
241
242 virtual ~WebHook() noexcept = default;
243 };
244
245 class DiscordCoreAPI_Dll WebHookVector {
246 public:
247 WebHookVector() noexcept = default;
248
249 operator std::vector<WebHook>();
250
251 WebHookVector(Value jsonData);
252
253 virtual ~WebHookVector() noexcept = default;
254
255 protected:
256 std::vector<WebHook> webHooks{};
257 };
258
259 /**@}*/
260
261 /**
262 * \addtogroup main_endpoints
263 * @{
264 */
265 /// \brief An interface class for the WebHook related Discord endpoints;
266 class DiscordCoreAPI_Dll WebHooks {
267 public:
268 static void initialize(DiscordCoreInternal::HttpsClient*);
269
270 /// \brief Creates a new WebHook.
271 /// \param dataPackage A GetMessageData structure.
272 /// \returns A CoRoutine containing a WebHook.
273 static CoRoutine<WebHook> createWebHookAsync(CreateWebHookData dataPackage);
274
275 /// \brief Collects a list of WebHooks from a chosen Channel.
276 /// \param dataPackage A GetChannelWebHooksData structure.
277 /// \returns A CoRoutine containing a WebHookVector.
278 static CoRoutine<std::vector<WebHook>> getChannelWebHooksAsync(GetChannelWebHooksData dataPackage);
279
280 /// \brief Collects a list of WebHooks from a chosen Guild.
281 /// \param dataPackage A GetGuildWebHooksData structure.
282 /// \returns A CoRoutine containing a WebHookVector.
283 static CoRoutine<std::vector<WebHook>> getGuildWebHooksAsync(GetGuildWebHooksData dataPackage);
284
285 /// \brief Collects a single WebHook.
286 /// \param dataPackage A GetWebHookData structure.
287 /// \returns A CoRoutine containing a WebHook.
288 static CoRoutine<WebHook> getWebHookAsync(GetWebHookData dataPackage);
289
290 /// \brief Collects a single WebHook, using the Token.
291 /// \param dataPackage A GetWebHookWithTokenData structure.
292 /// \returns A CoRoutine containing a WebHook.
293 static CoRoutine<WebHook> getWebHookWithTokenAsync(GetWebHookWithTokenData dataPackage);
294
295 /// \brief Modifies a single WebHook.
296 /// \param dataPackage A ModifyWebHookData structure.
297 /// \returns A CoRoutine containing a WebHook.
298 static CoRoutine<WebHook> modifyWebHookAsync(ModifyWebHookData dataPackage);
299
300 /// \brief Modifies a single WebHook, using its Token.
301 /// \param dataPackage A ModifyWebHookWithTokenData structure.
302 /// \returns A CoRoutine containing a WebHook.
303 static CoRoutine<WebHook> modifyWebHookWithTokenAsync(ModifyWebHookWithTokenData dataPackage);
304
305 /// \brief Deletes a single WebHook.
306 /// \param dataPackage A DeleteWebHookData structure.
307 /// \returns A CoRoutine containing void.
308 static CoRoutine<void> deleteWebHookAsync(DeleteWebHookData dataPackage);
309
310 /// \brief Deletes a single WebHook, using its Token.
311 /// \param dataPackage A DeleteWebHookWithTokenData structure.
312 /// \returns A CoRoutine containing void.
313 static CoRoutine<void> deleteWebHookWithTokenAsync(DeleteWebHookWithTokenData dataPackage);
314
315 /// \brief Executes a single WebHook.
316 /// \param dataPackage An ExecuteWebHookData structure.
317 /// \returns A CoRoutine containing a Message.
318 static CoRoutine<Message> executeWebHookAsync(ExecuteWebHookData dataPackage);
319
320 /// \brief Collects a WebHook Message.
321 /// \param dataPackage An GetWebHookMessageData structure.
322 /// \returns A CoRoutine containing a Message.
323 static CoRoutine<Message> getWebHookMessageAsync(GetWebHookMessageData dataPackage);
324
325 /// \brief Edits a WebHook Message.
326 /// \param dataPackage An EditWebHookMessageData structure.
327 /// \returns A CoRoutine containing a Message.
328 static CoRoutine<Message> editWebHookMessageAsync(EditWebHookData dataPackage);
329
330 /// \brief Deletes a WebHook Message.
331 /// \param dataPackage An DeleteWebHookMessageData structure.
332 /// \returns A CoRoutine containing a Message.
333 static CoRoutine<void> deleteWebHookMessageAsync(DeleteWebHookMessageData dataPackage);
334
335 protected:
336 static DiscordCoreInternal::HttpsClient* httpsClient;
337 };
338 /**@}*/
339
340}// namespace DiscordCoreAPI
ButtonStyle
Button styles.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:52
Allowable mentions for a Message.
For editing an Interaction response.
For creating an ephemeral follow up Message.
For editing a follow up Message.
An interface class for the Interaction related Discord endpoints.
For creating a new WebHook.
For editing a WebHook Message.
For collecting a list of WebHooks from a chosen Channel.
For collecting a list of WebHooks from a chosen Guild.
Collects a single WebHook.
Collects a single WebHook, using the Token and Id.
For deleting a WebHook, using its Token.
For getting a WebHook Message.
For deleting a WebHook Message.
An interface class for the WebHook related Discord endpoints;.