DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
ThreadEntities.cpp
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/// ThreadEntities.cpp - Source file for the thread-related stuff.
27/// Nov 29, 2021
28/// https://discordcoreapi.com
29/// \file ThreadEntities.cpp
30
34
35namespace jsonifier {
36
37 template<> struct core<discord_core_api::forum_thread_message_data> {
39 static constexpr auto parseValue =
40 createObject("attachments", &value_type::attachments, "components", &value_type::components, "allowedMentions", &value_type::allowedMentions, "stickerIds",
41 &value_type::stickerIds, "embeds", &value_type::embeds, "files", &value_type::files, "content", &value_type::content, "flags", &value_type::flags);
42 };
43
44 template<> struct core<discord_core_api::start_thread_with_message_data> {
46 static constexpr auto parseValue = createObject("autoArchiveDuration", &value_type::autoArchiveDuration, "rateLimitPerUser", &value_type::rateLimitPerUser, "threadName",
47 &value_type::threadName, "messageId", &value_type::messageId, "channelId", &value_type::channelId, "reason", &value_type::reason);
48 };
49
50 template<> struct core<discord_core_api::start_thread_without_message_data> {
52 static constexpr auto parseValue =
53 createObject("autoArchiveDuration", &value_type::autoArchiveDuration, "type", &value_type::type, "rateLimitPerUser", &value_type::rateLimitPerUser, "threadName",
54 &value_type::threadName, "channelId", &value_type::channelId, "reason", &value_type::reason, "invitable", &value_type::invitable);
55 };
56
57 template<> struct core<discord_core_api::start_thread_in_forum_channel_data> {
59 static constexpr auto parseValue = createObject("autoArchiveDuration", &value_type::autoArchiveDuration, "message", &value_type::message, "rateLimitPerUser",
60 &value_type::rateLimitPerUser, "channelId", &value_type::channelId, "reason", &value_type::reason, "name", &value_type::name);
61 };
62
63}
64
65namespace discord_core_api {
66
67 void threads::initialize(discord_core_internal::https_client* client) {
68 threads::httpsClient = client;
69 }
70
72 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Thread_With_Message };
73 co_await newThreadAwaitable<thread_data>();
74 workload.workloadClass = discord_core_internal::https_workload_class::Post;
75 workload.relativePath = "/channels/" + dataPackage.channelId + "/messages/" + dataPackage.messageId + "/threads";
76 parser.serializeJson<true>(dataPackage, workload.content);
77 workload.callStack = "threads::startThreadWithMessageAsync()";
78 if (dataPackage.reason != "") {
79 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
80 }
81 thread_data returnData{};
82 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
83 co_return returnData;
84 }
85
87 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Thread_Without_Message };
88 co_await newThreadAwaitable<thread_data>();
89 workload.workloadClass = discord_core_internal::https_workload_class::Post;
90 workload.relativePath = "/channels/" + dataPackage.channelId + "/threads";
91 parser.serializeJson<true>(dataPackage, workload.content);
92 workload.callStack = "threads::startThreadWithoutMessageAsync()";
93 if (dataPackage.reason != "") {
94 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
95 }
96 thread_data returnData{};
97 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
98 co_return returnData;
99 }
100
102 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Thread_In_Forum_Channel };
103 co_await newThreadAwaitable<thread_data>();
104 workload.workloadClass = discord_core_internal::https_workload_class::Post;
105 workload.relativePath = "/channels/" + dataPackage.channelId + "/threads";
106 parser.serializeJson<true>(dataPackage, workload.content);
107 workload.callStack = "threads::startThreadInForumChannelAsync()";
108 if (dataPackage.reason != "") {
109 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
110 }
111 thread_data returnData{};
112 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
113 co_return returnData;
114 }
115
117 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Put_Self_In_Thread };
118 co_await newThreadAwaitable<void>();
119 workload.workloadClass = discord_core_internal::https_workload_class::Put;
120 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members/@me";
121 workload.callStack = "threads::joinThreadAsync()";
122 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload));
123 co_return;
124 }
125
127 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Put_Thread_Member };
128 co_await newThreadAwaitable<void>();
129 workload.workloadClass = discord_core_internal::https_workload_class::Put;
130 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members/" + dataPackage.userId;
131 workload.callStack = "threads::addThreadMemberAsync()";
132 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload));
133 co_return;
134 }
135
137 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Self_From_Thread };
138 co_await newThreadAwaitable<void>();
139 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
140 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members/@me";
141 workload.callStack = "threads::leaveThreadAsync()";
142 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload));
143 co_return;
144 }
145
147 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Thread_Member };
148 co_await newThreadAwaitable<void>();
149 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
150 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members/" + dataPackage.userId;
151 workload.callStack = "threads::removeThreadMemberAsync()";
152 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload));
153 co_return;
154 }
155
157 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Thread_Member };
158 co_await newThreadAwaitable<thread_member_data>();
159 workload.workloadClass = discord_core_internal::https_workload_class::Get;
160 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members/" + dataPackage.userId;
161 workload.callStack = "threads::getThreadMemberAsync()";
162 thread_member_data returnData{};
163 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
164 co_return returnData;
165 }
166
168 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Thread_Members };
169 co_await newThreadAwaitable<jsonifier::vector<thread_member_data>>();
170 workload.workloadClass = discord_core_internal::https_workload_class::Get;
171 workload.relativePath = "/channels/" + dataPackage.channelId + "/thread-members";
172 workload.callStack = "threads::getThreadMembersAsync()";
173 jsonifier::vector<thread_member_data> returnData{};
174 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
175 co_return returnData;
176 }
177
179 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Active_Threads };
180 co_await newThreadAwaitable<active_threads_data>();
181 workload.workloadClass = discord_core_internal::https_workload_class::Get;
182 workload.relativePath = "/channels/" + dataPackage.channelId + "/threads/active";
183 workload.callStack = "threads::getActiveThreadsAsync()";
184 active_threads_data returnData{};
185 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
186 co_return returnData;
187 }
188
190 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Public_Archived_Threads };
191 co_await newThreadAwaitable<archived_threads_data>();
192 workload.workloadClass = discord_core_internal::https_workload_class::Get;
193 workload.relativePath = "/channels/" + dataPackage.channelId + "/threads/archived/public";
194 if (dataPackage.before != "") {
195 workload.relativePath += "?before=" + dataPackage.before;
196 if (dataPackage.limit != 0) {
197 workload.relativePath += "&limit=" + jsonifier::toString(dataPackage.limit);
198 }
199 } else if (dataPackage.limit != 0) {
200 workload.relativePath += "?limit=" + jsonifier::toString(dataPackage.limit);
201 }
202 workload.callStack = "threads::getPublicArchivedThreadsAsync()";
203 archived_threads_data returnData{};
204 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
205 co_return returnData;
206 }
207
209 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Private_Archived_Threads };
210 co_await newThreadAwaitable<archived_threads_data>();
211 workload.workloadClass = discord_core_internal::https_workload_class::Get;
212 workload.relativePath = "/channels/" + dataPackage.channelId + "/threads/archived/protected";
213 if (dataPackage.before != "") {
214 workload.relativePath += "?before=" + dataPackage.before;
215 if (dataPackage.limit != 0) {
216 workload.relativePath += "&limit=" + jsonifier::toString(dataPackage.limit);
217 }
218 } else if (dataPackage.limit != 0) {
219 workload.relativePath += "?limit=" + jsonifier::toString(dataPackage.limit);
220 }
221 workload.callStack = "threads::getPrivateArchivedThreadsAsync()";
222 archived_threads_data returnData{};
223 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
224 co_return returnData;
225 }
226
228 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Joined_Private_Archived_Threads };
229 co_await newThreadAwaitable<archived_threads_data>();
230 workload.workloadClass = discord_core_internal::https_workload_class::Get;
231 workload.relativePath = "/channels/" + dataPackage.channelId + "/users/@me/threads/archived/protected";
232 if (dataPackage.before != "") {
233 workload.relativePath += "?before=" + dataPackage.before;
234 if (dataPackage.limit != 0) {
235 workload.relativePath += "&limit=" + jsonifier::toString(dataPackage.limit);
236 }
237 } else if (dataPackage.limit != 0) {
238 workload.relativePath += "?limit=" + jsonifier::toString(dataPackage.limit);
239 }
240 workload.callStack = "threads::getJoinedPrivateArchivedThreadsAsync()";
241 archived_threads_data returnData{};
242 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
243 co_return returnData;
244 }
245
247 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Active_Threads };
248 co_await newThreadAwaitable<active_threads_data>();
249 workload.workloadClass = discord_core_internal::https_workload_class::Get;
250 workload.relativePath = "/guilds/" + dataPackage.guildId + "/threads/active";
251 workload.callStack = "threads::listActiveThreadsAsync()";
252 active_threads_data returnData{};
253 threads::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
254 co_return returnData;
255 }
256
257 discord_core_internal::https_client* threads::httpsClient{};
258}
A co_routine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:83
Represents a single thread_data.
Data for a single member of a thread_data.
static co_routine< archived_threads_data > getPublicArchivedThreadsAsync(const get_public_archived_threads_data dataPackage)
Collects a list of public archived threads from a given channel.
static co_routine< void > leaveThreadAsync(const leave_thread_data dataPackage)
Leaves a thread_data.
static co_routine< void > joinThreadAsync(const join_thread_data dataPackage)
Joins a thread_data.
static co_routine< thread_data > startThreadInForumChannelAsync(const start_thread_in_forum_channel_data dataPackage)
Starts a thread_data, in a forum channel.
static co_routine< void > addThreadMemberAsync(const add_thread_member_data dataPackage)
Adds a new user_data to a chosen thread_data.
static co_routine< thread_member_data > getThreadMemberAsync(const get_thread_member_data dataPackage)
Collects a thread_member if they exist.
static co_routine< active_threads_data > getActiveThreadsAsync(const get_active_threads_data dataPackage)
Collects a list of threads from a given channel.
static co_routine< active_threads_data > getActiveGuildThreadsAsync(const get_active_guild_threads_data dataPackage)
Lists all of the active threads of a chosen guild.
static co_routine< archived_threads_data > getPrivateArchivedThreadsAsync(const get_private_archived_threads_data dataPackage)
Collects a list of protected archived threads from a given channel.
static co_routine< jsonifier::vector< thread_member_data > > getThreadMembersAsync(const get_thread_members_data dataPackage)
Collects a list of thread_members if they exist.
static co_routine< archived_threads_data > getJoinedPrivateArchivedThreadsAsync(const get_joined_private_archived_threads_data dataPackage)
Collects a list of joined protected archived threads from a given channel.
static co_routine< thread_data > startThreadWithMessageAsync(const start_thread_with_message_data dataPackage)
Starts a thread_data, based on a starting message_data.
static co_routine< thread_data > startThreadWithoutMessageAsync(const start_thread_without_message_data dataPackage)
Starts a thread_data, not based on a starting message_data.
static co_routine< void > removeThreadMemberAsync(const remove_thread_member_data dataPackage)
Removes a user from a chosen thread_data.
The main namespace for the forward-facing interfaces.
Data representing an active thread_data.
For adding a chosen user_data to a chosen thread_data.
snowflake channelId
The id of the thread_data to join.
snowflake userId
The id of the user_data to add to the thread_data.
Data representing an archived thread_data.
For listing the active threads in a chosen guild.
snowflake guildId
The guild from which to list the threads from.
For collecting the list of active threads.
snowflake channelId
The id of the channel_data to collect the threads from.
For collecting joined protected archived threads from a given channel.
snowflake channelId
The channel_data to acquire the threads from.
jsonifier::string before
Returns threads before this timeStamp.
int32_t limit
Maximum number of threads to return.
For collecting protected archived threads from a given channel.
jsonifier::string before
Returns threads before this timeStamp.
snowflake channelId
The channel_data to acquire the threads from.
int32_t limit
Maximum number of threads to return.
For collecting puiblic archived threads from a given channel.
snowflake channelId
The channel_data to acquire the threads from.
jsonifier::string before
Returns threads before this timeStamp.
int32_t limit
Maximum number of threads to return.
For collecting a thread_member responseData structure for a given thread_member.
snowflake channelId
The id of the thread_data to collect them from.
snowflake userId
The id of the user_data to collect from the thread_data.
For collecting the list of thread_members from a thread_data.
snowflake channelId
The id of the thread_data to collect them from.
For joining a thread_data.
snowflake channelId
The id of the thread_data to join.
For leaving a thread_data.
snowflake channelId
The id of the thread_data to leave.
For removing a chosen user_data from a thread_data.
snowflake channelId
The id of the thread_data to remove them from.
snowflake userId
The id of the user_data to remove from the thread_data.
For starting a thread_data, in a forum channel.
jsonifier::string reason
Reason for starting the thread_data.
For starting a thread_data, based on a message.
snowflake channelId
The channel_data to start the thread_data in.
jsonifier::string reason
Reason for starting the thread_data.
snowflake messageId
The message snowflake to base the thread_data off of.
For starting a thread_data, not based on a message.
jsonifier::string reason
Reason for starting the thread_data.
snowflake channelId
The channel_data to start the thread_data in.