40 static constexpr auto parseValue =
41 createObject(
"components", &value_type::components,
"allowed_mentions", &value_type::allowedMentions,
"embeds", &value_type::embeds,
"files", &value_type::files,
42 "custom_id", &value_type::customId,
"content", &value_type::content,
"title", &value_type::title,
"flags", &value_type::flags,
"tts", &value_type::tts);
47 static constexpr auto parseValue =
48 createObject(
"components", &value_type::components,
"allowed_mentions", &value_type::allowedMentions,
"embeds", &value_type::embeds,
"files", &value_type::files,
49 "custom_id", &value_type::customId,
"content", &value_type::content,
"title", &value_type::title,
"flags", &value_type::flags,
"tts", &value_type::tts);
54 static constexpr auto parseValue =
55 createObject(
"components", &value_type::components,
"allowed_mentions", &value_type::allowedMentions,
"embeds", &value_type::embeds,
"files", &value_type::files,
56 "custom_id", &value_type::customId,
"content", &value_type::content,
"title", &value_type::title,
"flags", &value_type::flags,
"tts", &value_type::tts);
61 static constexpr auto parseValue = createObject(
"messages", &value_type::messageIds);
67 template<> unordered_map<jsonifier::string, unbounded_message_block<message_data>*> object_collector<message_data>::objectsBuffersMap{};
69 template<> object_collector<message_data>::object_collector() {
70 collectorId = jsonifier::toString(std::chrono::duration_cast<milliseconds>(hrclock::now().time_since_epoch()).count());
71 object_collector::objectsBuffersMap[collectorId] = &objectsBuffer;
74 template<>
void object_collector<message_data>::run(std::coroutine_handle<
76 int64_t startingTime =
static_cast<int64_t
>(std::chrono::duration_cast<milliseconds>(hrclock::now().time_since_epoch()).count());
77 int64_t elapsedTime{};
78 while (elapsedTime < msToCollectFor && !coroHandle.promise().stopRequested()) {
79 message_data message{};
80 waitForTimeToPass<message_data>(objectsBuffer, message,
static_cast<uint64_t
>(msToCollectFor -
static_cast<uint64_t
>(elapsedTime)));
81 if (filteringFunction(message)) {
82 objectReturnData.objects.emplace_back(message);
84 if (
static_cast<int32_t
>(objectReturnData.objects.size()) >= quantityOfObjectsToCollect) {
88 elapsedTime = std::chrono::duration_cast<milliseconds>(hrclock::now().time_since_epoch()).count() - startingTime;
93 int32_t msToCollectForNew, object_filter<message_data> filteringFunctionNew) {
94 auto coroHandle =
co_await newThreadAwaitable<object_collector_return_data, false>();
95 quantityOfObjectsToCollect = quantityToCollect;
96 filteringFunction = filteringFunctionNew;
97 msToCollectFor = msToCollectForNew;
100 co_return objectReturnData;
103 template<> object_collector<message_data>::~object_collector() {
104 if (object_collector::objectsBuffersMap.contains(collectorId)) {
105 object_collector::objectsBuffersMap.erase(collectorId);
109 create_message_data::create_message_data(
const snowflake channelIdNew) {
110 channelId = channelIdNew;
113 create_message_data::create_message_data(respond_to_input_event_data dataPackage) {
114 channelId = dataPackage.channelId;
116 for (
auto& value: dataPackage.components) {
117 components.emplace_back(value);
120 for (
auto& value: dataPackage.embeds) {
121 embeds.emplace_back(value);
123 tts = dataPackage.tts;
126 create_message_data::create_message_data(message_data dataPackage) {
127 channelId = dataPackage.channelId;
128 messageReference.
channelId = dataPackage.channelId;
130 messageReference.
guildId = dataPackage.guildId;
131 tts = dataPackage.tts;
134 create_message_data::create_message_data(input_event_data dataPackage) {
135 channelId = dataPackage.getChannelData().
id;
138 send_dmdata::send_dmdata(respond_to_input_event_data dataPackage) {
139 targetUserId = dataPackage.targetUserId;
141 for (
auto& value: dataPackage.components) {
142 components.emplace_back(value);
145 for (
auto& value: dataPackage.embeds) {
146 embeds.emplace_back(value);
148 channelId = dataPackage.targetUserId;
149 tts = dataPackage.tts;
152 edit_message_data::edit_message_data(input_event_data dataPackage) {
153 channelId = dataPackage.getChannelData().
id;
154 messageId = dataPackage.getMessageData().
id;
157 edit_message_data::edit_message_data(respond_to_input_event_data dataPackage) {
158 allowedMentions = dataPackage.allowedMentions;
159 channelId = dataPackage.channelId;
160 messageId = dataPackage.messageId;
161 for (
auto& value: dataPackage.components) {
162 components.emplace_back(value);
164 content = dataPackage.content;
165 for (
auto& value: dataPackage.embeds) {
166 embeds.emplace_back(value);
170 delete_message_data::delete_message_data(
const message_data& messageToDelete) {
176 void messages::initialize(discord_core_internal::https_client* client) {
177 messages::httpsClient = client;
181 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Messages };
182 co_await newThreadAwaitable<jsonifier::vector<message_data>>();
183 workload.workloadClass = discord_core_internal::https_workload_class::Get;
184 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages";
186 workload.relativePath +=
"?around=" + dataPackage.
aroundThisId;
187 if (dataPackage.
limit != 0) {
188 workload.relativePath +=
"&limit=" + jsonifier::toString(dataPackage.
limit);
190 workload.relativePath +=
"&limit=1";
193 workload.relativePath +=
"?before=" + dataPackage.
beforeThisId;
194 if (dataPackage.
limit != 0) {
195 workload.relativePath +=
"&limit=" + jsonifier::toString(dataPackage.
limit);
197 workload.relativePath +=
"&limit=1";
200 workload.relativePath +=
"?after=" + dataPackage.
afterThisId;
201 if (dataPackage.
limit != 0) {
202 workload.relativePath +=
"&limit=" + jsonifier::toString(dataPackage.
limit);
204 workload.relativePath +=
"&limit=1";
207 if (dataPackage.
limit != 0) {
208 workload.relativePath +=
"?limit=" + jsonifier::toString(dataPackage.
limit);
210 workload.relativePath +=
"&limit=1";
213 workload.callStack =
"messages::getMessagesAsync()";
214 jsonifier::vector<message_data> returnData{};
215 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
216 co_return returnData;
220 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Message };
221 co_await newThreadAwaitable<message_data>();
222 workload.workloadClass = discord_core_internal::https_workload_class::Get;
223 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
id;
224 workload.callStack =
"messages::getMessageAsync()";
226 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
227 co_return returnData;
231 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Message };
232 co_await newThreadAwaitable<message_data>();
233 workload.workloadClass = discord_core_internal::https_workload_class::Post;
234 workload.relativePath =
"/channels/" + dataPackage.channelId +
"/messages";
235 if (dataPackage.files.size() > 0) {
236 workload.payloadType = discord_core_internal::payload_type::Multipart_Form;
237 parser.serializeJson<
true>(dataPackage, workload.content);
239 parser.serializeJson<
true>(dataPackage, workload.content);
241 workload.callStack =
"messages::createMessageAsync()";
243 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
244 co_return returnData;
248 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Crosspost_Message };
249 co_await newThreadAwaitable<message_data>();
250 workload.workloadClass = discord_core_internal::https_workload_class::Post;
251 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/crosspost";
252 workload.callStack =
"messages::crosspostMessageAsync()";
254 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
255 co_return returnData;
259 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Message };
260 co_await newThreadAwaitable<message_data>();
261 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
262 workload.relativePath =
"/channels/" + dataPackage.channelId +
"/messages/" + dataPackage.messageId;
263 if (dataPackage.files.size() > 0) {
264 workload.payloadType = discord_core_internal::payload_type::Multipart_Form;
265 parser.serializeJson<
true>(dataPackage, workload.content);
267 parser.serializeJson<
true>(dataPackage, workload.content);
269 workload.callStack =
"messages::editMessageAsync()";
271 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
272 co_return returnData;
276 discord_core_internal::https_workload_data workload{};
278 if (!hasTimeElapsedNew) {
279 workload = discord_core_internal::https_workload_type::Delete_Message;
281 workload = discord_core_internal::https_workload_type::Delete_Message_Old;
283 co_await newThreadAwaitable<void>();
285 std::this_thread::sleep_for(milliseconds{ dataPackage.
timeDelay });
287 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
288 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId;
289 workload.callStack =
"messages::deleteMessageAsync()";
290 if (dataPackage.
reason !=
"") {
291 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
293 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload));
298 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Bulk_Delete_Messages };
299 co_await newThreadAwaitable<void>();
300 workload.workloadClass = discord_core_internal::https_workload_class::Post;
301 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/bulk-delete";
302 parser.serializeJson<
true>(dataPackage, workload.content);
303 if (dataPackage.
reason !=
"") {
304 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
306 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload));
311 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Pinned_Messages };
312 co_await newThreadAwaitable<jsonifier::vector<message_data>>();
313 workload.workloadClass = discord_core_internal::https_workload_class::Get;
314 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/pins";
315 workload.callStack =
"messages::getPinnedMessagesAsync()";
316 jsonifier::vector<message_data> returnData{};
317 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
318 co_return returnData;
322 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Put_Pin_Message };
323 co_await newThreadAwaitable<void>();
324 workload.workloadClass = discord_core_internal::https_workload_class::Put;
325 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/pins/" + dataPackage.
messageId;
326 workload.callStack =
"messages::pinMessageAsync()";
327 if (dataPackage.
reason !=
"") {
328 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
330 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload));
335 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Pin_Message };
336 co_await newThreadAwaitable<void>();
337 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
338 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/pins/" + dataPackage.
messageId;
339 workload.callStack =
"messages::unpinMessageAsync()";
340 if (dataPackage.
reason !=
"") {
341 workload.headersToInsert[
"x-audit-log-reason"] = dataPackage.
reason;
343 messages::httpsClient->submitWorkloadAndGetResult(std::move(workload));
A co_routine - representing a potentially asynchronous operation/function.
For sending Https requests.
Data structure representing a single message_data.
Message response base, for responding to messages.
message_response_base & addContent(jsonifier::string_view dataPackage)
For setting the message content in a response.
message_response_base & addAllowedMentions(const allowed_mentions_data dataPackage)
For setting the allowable mentions in a response.
static co_routine< void > pinMessageAsync(const pin_message_data dataPackage)
Pins a message to a given channel.
static co_routine< void > deleteMessagesBulkAsync(const delete_messages_bulk_data dataPackage)
Deletes a collection of messages.
static co_routine< message_data > getMessageAsync(const get_message_data dataPackage)
Collects a message from the discord servers.
static co_routine< void > unpinMessageAsync(const unpin_message_data dataPackage)
Unpins a message from a given channel.
static co_routine< message_data > crosspostMessageAsync(const crosspost_message_data dataPackage)
Crossposts a message from a news channel_data to the following channels.
static co_routine< message_data > editMessageAsync(const edit_message_data dataPackage)
Edit a message.
static co_routine< void > deleteMessageAsync(const delete_message_data dataPackage)
Deletes a message.
static co_routine< jsonifier::vector< message_data > > getPinnedMessagesAsync(const get_pinned_messages_data dataPackage)
Collects a collection of pinned messages from the discord servers.
static co_routine< jsonifier::vector< message_data > > getMessagesAsync(const get_messages_data dataPackage)
Collects a collection of message from the discord servers.
static co_routine< message_data > createMessageAsync(const create_message_data dataPackage)
Creates a new message_data.
co_routine< object_collector_return_data, false > collectObjects(int32_t quantityToCollect, int32_t msToCollectForNew, object_filter< value_type > filteringFunctionNew)
Begin waiting for objects.
uint64_t id
The snowflake id.
bool hasTimeElapsed(int64_t days, int64_t hours, int64_t minutes) const
Checks if a certain time duration has elapsed.
The main namespace for the forward-facing interfaces.
For crossposting a message.
snowflake messageId
snowflake of the message to be crossposted.
snowflake channelId
channel_data within which to crosspost the message from.
snowflake messageId
The message snowflake of the message to delete.
snowflake channelId
The channel snowflake of the message to delete.
jsonifier::string reason
The reason for deleting the message_data.
int32_t timeDelay
Number of milliseconds to wait before deleting the message_data.
time_stamp timeStamp
The created-at timeStamp of the original message.
For deleting a bulk of messages.
snowflake channelId
channel_data within which to delete the messages.
jsonifier::string reason
The reason for deleting the messages.
snowflake id
The id of the message to collect.
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.
snowflake guildId
snowflake of the guild that the referenced message was sent in.
snowflake messageId
snowflake of the message to reference.
snowflake channelId
snowflake of the channel_data that the referenced message was sent in.
Object_collector_return_data responseData.c.
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.