DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
MessageEntities.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/// MessageEntities.hpp - Header for the message_data related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file MessageEntities.hpp
30#pragma once
31
35
36namespace discord_core_api {
37
38 /**
39 * \addtogroup foundation_entities
40 * @{
41 */
42
43 /// @brief Typedef for the message filter.
44 template<typename value_type> using object_filter = std::function<bool(value_type)>;
45
46 /// @brief Object collector, for collecting objects from a channel.
47 template<typename value_type> class DiscordCoreAPI_Dll object_collector {
48 public:
49 /// @brief Object_collector_return_data responseData.c
51 jsonifier::vector<value_type> objects{};///< A vector of collected objects.
52 };
53
54 static unordered_map<jsonifier::string, unbounded_message_block<value_type>*> objectsBuffersMap;
55
57
58 /// @brief Begin waiting for objects.
59 /// @param quantityToCollect maximum quantity of objects to collect before returning the results.
60 /// @param msToCollectForNew maximum number of milliseconds to wait for objects before returning the results.
61 /// @param filteringFunctionNew a filter function to apply to new objects, where returning "true" from the function results in a object being stored.
62 /// @return A object_collector_return_data structure.
63 co_routine<object_collector_return_data, false> collectObjects(int32_t quantityToCollect, int32_t msToCollectForNew, object_filter<value_type> filteringFunctionNew);
64
65 void run(std::coroutine_handle<
67
69
70 protected:
72 object_collector_return_data objectReturnData{};
73 object_filter<value_type> filteringFunction{};
74 int32_t quantityOfObjectsToCollect{};
75 jsonifier::string collectorId{};
76 int32_t msToCollectFor{};
77 };
78
79 using message_collector = object_collector<message_data>;
80
81 /// @brief For getting a collection of messages.
83 snowflake beforeThisId{};///< Before this id.
84 snowflake aroundThisId{};///< Around this id.
85 snowflake afterThisId{};///< After this id.
86 snowflake channelId{};///< channel_data from which to collect the messages.
87 int32_t limit{};///< Limit of messages to collect.
88 };
89
90 /// @brief For getting a message.
92 snowflake channelId{};///< The channel_data from which to collect the message_data.
93 snowflake id{};///< The id of the message to collect.
94 };
95
96 /// @brief For creating a message.
97 class DiscordCoreAPI_Dll create_message_data : public message_response_base {
98 public:
99 template<typename value_type> friend struct jsonifier::core;
100 friend class input_events;
101 friend class messages;
102
103 create_message_data(const snowflake channelIdNew);
104
106
108
110
111 snowflake channelId{};
112
113 create_message_data() = default;
114
115 protected:
116 jsonifier::vector<attachment_data> attachments{};
117 message_reference_data messageReference{};
118 jsonifier::vector<jsonifier::string> stickerIds{};
119 };
120
121 /// @brief For sending a direct-message.
122 class DiscordCoreAPI_Dll send_dmdata : public create_message_data {
123 public:
124 friend class input_events;
125
127
128 protected:
129 snowflake targetUserId{};
130 };
131
132 /// @brief For crossposting a message.
134 snowflake messageId{};///< snowflake of the message to be crossposted.
135 snowflake channelId{};///< channel_data within which to crosspost the message from.
136 };
137
138 /// @brief For editing a message.
139 class DiscordCoreAPI_Dll edit_message_data : public message_response_base {
140 public:
141 template<typename value_type> friend struct jsonifier::core;
142 friend class input_events;
143 friend class messages;
144
146
148
149 protected:
150 jsonifier::vector<attachment_data> attachments{};
151 snowflake channelId{};
152 snowflake messageId{};
153 int32_t flags{};
154
155 edit_message_data() = default;
156 };
157
158 /// @brief For deleting a message.
159 struct DiscordCoreAPI_Dll delete_message_data {
160 public:
161 delete_message_data(const message_data& messageToDelete);
162 time_stamp timeStamp{};///< The created-at timeStamp of the original message.
163 snowflake channelId{};///< The channel snowflake of the message to delete.
164 snowflake messageId{};///< The message snowflake of the message to delete.
165 jsonifier::string reason{};///< The reason for deleting the message_data.
166 int32_t timeDelay{};///< Number of milliseconds to wait before deleting the message_data.
167 };
168
169 /// @brief For deleting a bulk of messages.
171 jsonifier::vector<snowflake> messageIds{};///< Array of message ids to delete.
172 snowflake channelId{};///< channel_data within which to delete the messages.
173 jsonifier::string reason{};///< The reason for deleting the messages.
174 };
175
176 /// @brief For getting a collection of pinned messages.
178 snowflake channelId{};///< The channel_data from which to collect pinned messages.
179 };
180
181 /// @brief For pinning a single message_data.
183 snowflake channelId{};///< The channel_data within which to pin the message_data.
184 snowflake messageId{};///< The message which you would like to pin.
185 jsonifier::string reason{};///< Reason for pinning this message_data.
186 };
187
188 /// @brief For unpinning a single message_data.
190 snowflake channelId{};///< The channel_data within which to unpin the message_data.
191 snowflake messageId{};///< The message which you would like to unpin.
192 jsonifier::string reason{};///< Reason for pinning this message_data.
193 };
194
195 /**@}*/
196
197 /**
198 * \addtogroup main_endpoints
199 * @{
200 */
201 /// @brief An interface class for the message_data related discord endpoints.
202 class DiscordCoreAPI_Dll messages {
203 public:
204 static void initialize(discord_core_internal::https_client*);
205
206 /// @brief Collects a collection of message from the discord servers
207 /// @param dataPackage a get_messages_data structure.
208 /// @return A co_routine containing a jsonifier::vector<message_data>.
209 static co_routine<jsonifier::vector<message_data>> getMessagesAsync(const get_messages_data dataPackage);
210
211 /// @brief Collects a message from the discord servers.
212 /// @param dataPackage a get_message_data structure.
213 /// @return A co_routine containing a message.
214 static co_routine<message_data> getMessageAsync(const get_message_data dataPackage);
215
216 /// @brief Creates a new message_data.
217 /// @param dataPackage a create_message_data structure.
218 /// @return A co_routine containing a message.
219 static co_routine<message_data> createMessageAsync(const create_message_data dataPackage);
220
221 /// @brief Crossposts a message from a news channel_data to the following channels.
222 /// @param dataPackage a crosspost_message_data structure.
223 /// @return A co_routine containing void.
224 static co_routine<message_data> crosspostMessageAsync(const crosspost_message_data dataPackage);
225
226 /// @brief Edit a message.
227 /// @param dataPackage an edit_message_data structure.
228 /// @return A co_routine containing a message.
229 static co_routine<message_data> editMessageAsync(const edit_message_data dataPackage);
230
231 /// @brief Deletes a message.
232 /// @param dataPackage a delete_message_data structure.
233 /// @return A co_routine containing void.
234 static co_routine<void> deleteMessageAsync(const delete_message_data dataPackage);
235
236 /// @brief Deletes a collection of messages.
237 /// @param dataPackage a delete_messages_bulk_data structure.
238 /// @return A co_routine containing void.
239 static co_routine<void> deleteMessagesBulkAsync(const delete_messages_bulk_data dataPackage);
240
241 /// @brief Collects a collection of pinned messages from the discord servers.
242 /// @param dataPackage a get_pinned_messages_data structure.
243 /// @return A co_routine containing a jsonifier::vector<message_data>.
244 static co_routine<jsonifier::vector<message_data>> getPinnedMessagesAsync(const get_pinned_messages_data dataPackage);
245
246 /// @brief Pins a message to a given channel.
247 /// @param dataPackage a pin_message_data structure.
248 /// @return A co_routine containing void.
249 static co_routine<void> pinMessageAsync(const pin_message_data dataPackage);
250
251 /// @brief Unpins a message from a given channel.
252 /// @param dataPackage an unpin_message_data structure.
253 /// @return A co_routine containing void.
254 static co_routine<void> unpinMessageAsync(const unpin_message_data dataPackage);
255
256 protected:
257 static discord_core_internal::https_client* httpsClient;
258 };
259 /**@}*/
260
261}
A co_routine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:83
Data representing an input-event, which is any message or interaction that is coming into the bot as ...
For handling user_data input - messages or interactions.
Definition: InputEvents.hpp:43
Data structure representing a single message_data.
Message response base, for responding to messages.
An interface class for the message_data related discord endpoints.
Object collector, for collecting objects from a channel.
co_routine< object_collector_return_data, false > collectObjects(int32_t quantityToCollect, int32_t msToCollectForNew, object_filter< value_type > filteringFunctionNew)
Begin waiting for objects.
Data for responding to an input-event.
For sending a direct-message.
A class representing a snowflake identifier with various operations.
Definition: Base.hpp:680
A class that extends time_stamp_base to provide additional functionality.
Definition: Base.hpp:618
A thread-safe messaging block for data-structures.
std::function< bool(value_type)> object_filter
Typedef for the message filter.
The main namespace for the forward-facing interfaces.
snowflake messageId
snowflake of the message to be crossposted.
snowflake channelId
channel_data within which to crosspost the message from.
For deleting a bulk of messages.
jsonifier::vector< snowflake > messageIds
Array of message ids to delete.
snowflake channelId
channel_data within which to delete the messages.
jsonifier::string reason
The reason for deleting the messages.
snowflake channelId
The channel_data from which to collect the message_data.
For getting a collection of messages.
snowflake aroundThisId
Around this id.
snowflake afterThisId
After this id.
snowflake beforeThisId
Before this id.
int32_t limit
Limit of messages to collect.
snowflake channelId
channel_data from which to collect the messages.
For getting a collection of pinned messages.
snowflake channelId
The channel_data from which to collect pinned messages.
For pinning a single message_data.
snowflake messageId
The message which you would like to pin.
snowflake channelId
The channel_data within which to pin the message_data.
jsonifier::string reason
Reason for pinning this message_data.
For unpinning a single message_data.
jsonifier::string reason
Reason for pinning this message_data.
snowflake channelId
The channel_data within which to unpin the message_data.
snowflake messageId
The message which you would like to unpin.