DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
ThreadEntities.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/// ThreadEntities.hpp - Header file for the thread-related stuff.
22/// Nov 29, 2021
23/// https://discordcoreapi.com
24/// \file ThreadEntities.hpp
25
26#pragma once
27
28#ifndef THREAD_ENTITIES
29 #define THREAD_ENTITIES
30
34
35namespace DiscordCoreAPI {
36
37 /**
38 * \addtogroup foundation_entities
39 * @{
40 */
41
42 /// For starting a Thread, based on a Message. \brief For starting a Thread, based on a Message.
43 struct DiscordCoreAPI_Dll StartThreadWithMessageData {
44 ThreadAutoArchiveDuration autoArchiveDuration{ ThreadAutoArchiveDuration::Shortest };///< The duration before it is auto-archived, in minutes.
45 Int32 rateLimitPerUser{ 0 };///< Integer amount of seconds a user has to wait before sending another message(0 - 21600).
46 String threadName{};///< The name of the new Thread.
47 Snowflake messageId{};///< The Message Id to base the Thread off of.
48 Snowflake channelId{};///< The Channel to start the Thread in.
49 String reason{};///< Reason for starting the Thread.
50
51 operator JsonObject();
52 };
53
54 /// For starting a Thread, not based on a Message. \brief For starting a Thread, not based on a Message.
55 struct DiscordCoreAPI_Dll StartThreadWithoutMessageData {
56 ThreadAutoArchiveDuration autoArchiveDuration{ ThreadAutoArchiveDuration::Shortest };///< The duration before it is auto-archived, in minutes.
57 ThreadType type{ ThreadType::Guild_Public_Thread };///< Type of Thread to create.
58 Int32 rateLimitPerUser{ 0 };///< Integer amount of seconds a user has to wait before sending another message(0 - 21600).
59 String threadName{};///< The name of the new Thread.
60 Snowflake channelId{};///< The Channel to start the Thread in.
61 Bool invitable{ false };///< Whether non-moderators can add other non - moderators to a thread; only available when creating a private thread.
62 String reason{};///< Reason for starting the Thread.
63
64 operator JsonObject();
65 };
66
67 /// For starting a Thread, in a forum channel. \brief For starting a Thread, in a forum channel.
68 struct DiscordCoreAPI_Dll StartThreadInForumChannelData {
69 ThreadAutoArchiveDuration autoArchiveDuration{ ThreadAutoArchiveDuration::Longest };/// Duration in minutes to automatically archive the thread.
70 ForumThreadMessageData message{};///< A forum thread message params object contents of the first message in the forum thread.
71 Int32 rateLimitPerUser{};///< Integer amount of seconds a user has to wait before sending another message(0 - 21600).
72 Snowflake channelId{};///< The id of the channel.
73 String reason{};///< Reason for starting the Thread.
74 String name{};///< 1-100 character channel name auto_archive_duration.
75
76 operator JsonObject();
77 };
78
79 /// For joining a Thread. \brief For joining a Thread.
80 struct DiscordCoreAPI_Dll JoinThreadData {
81 Snowflake channelId{};///< The id of the Thread to join.
82 };
83
84 /// For adding a chosen User to a chosen Thread. \brief For adding a chosen User to a chosen Thread.
85 struct DiscordCoreAPI_Dll AddThreadMemberData {
86 Snowflake channelId{};///< The id of the Thread to join.
87 Snowflake userId{};///< The id of the User to add to the Thread.
88 };
89
90 /// For leaving a Thread. \brief For leaving a Thread.
91 struct DiscordCoreAPI_Dll LeaveThreadData {
92 Snowflake channelId{};///< The id of the Thread to leave.
93 };
94
95 /// For removing a chosen User from a Thread. \brief For removing a chosen User from a Thread.
96 struct DiscordCoreAPI_Dll RemoveThreadMemberData {
97 Snowflake channelId{};///< The id of the Thread to remove them from.
98 Snowflake userId{};///< The id of the User to remove from the Thread.
99 };
100
101 /// For collecting a ThreadMember responseData structure for a given ThreadMember. \brief For collecting a ThreadMember responseData structure for a given ThreadMember.
102 struct DiscordCoreAPI_Dll GetThreadMemberData {
103 Snowflake channelId{};///< The id of the Thread to collect them from.
104 Snowflake userId{};///< The id of the User to collect from the Thread.
105 };
106
107 /// For collecting the list of ThreadMembers from a Thread. \brief For collecting the list of ThreadMembers from a Thread.
108 struct DiscordCoreAPI_Dll GetThreadMembersData {
109 Snowflake channelId{};///< The id of the Thread to collect them from.
110 };
111
112 /// For collecting the list of active Threads. \brief For collecting the list of active Threads.
113 struct DiscordCoreAPI_Dll GetActiveThreadsData {
114 Snowflake channelId{};///< The id of the Channel to collect the Threads from.
115 };
116
117 /// For collecting puiblic archived Threads from a given Channel. \brief For collecting puiblic archived Threads from a given Channel.
118 struct DiscordCoreAPI_Dll GetPublicArchivedThreadsData {
119 Snowflake channelId{};///< The Channel to acquire the Threads from.
120 String before{};///< Returns threads before this timestamp.
121 Int32 limit{ 0 };///< Maximum number of threads to return.
122 };
123
124 /// For collecting private archived Threads from a given Channel. \brief For collecting private archived Threads from a given Channel.
125 struct DiscordCoreAPI_Dll GetPrivateArchivedThreadsData {
126 Snowflake channelId{};///< The Channel to acquire the Threads from.
127 String before{};///< Returns threads before this timestamp.
128 Int32 limit{ 0 };///< Maximum number of threads to return.
129 };
130
131 /// For collecting joined private archived Threads from a given Channel. \brief For collecting joined private archived Threads from a given Channel.
132 struct DiscordCoreAPI_Dll GetJoinedPrivateArchivedThreadsData {
133 Snowflake channelId{};///< The Channel to acquire the Threads from.
134 String before{};///< Returns threads before this timestamp.
135 Int32 limit{ 0 };///< Maximum number of threads to return.
136 };
137
138 /// For listing the active Threads in a chosen Guild. \brief For listing the active Threads in a chosen Guild.
139 struct DiscordCoreAPI_Dll GetActiveGuildThreadsData {
140 Snowflake guildId{};///< The Guild from which to list the Threads from.
141 };
142
143 /// Represents a single Thread. \brief Represents a single Thread.
144 class DiscordCoreAPI_Dll Thread : public Channel {
145 public:
146 Thread() noexcept = default;
147
148 Thread(simdjson::ondemand::value jsonObjectData);
149
150 virtual ~Thread() noexcept = default;
151 };
152
153 /**@}*/
154
155 /**
156 * \addtogroup main_endpoints
157 * @{
158 */
159 /// An interface class for the Thread related endpoints. \brief An interface class for the Thread related endpoints.
160 class DiscordCoreAPI_Dll Threads {
161 public:
162 static void initialize(DiscordCoreInternal::HttpsClient*);
163
164 /// Starts a Thread, based on a starting Message. \brief Starts a Thread, based on a starting Message.
165 /// \param dataPackage A StartThreadWithMessageData structure.
166 /// \returns A CoRoutine containing a Channel.
167 static CoRoutine<Thread> startThreadWithMessageAsync(StartThreadWithMessageData dataPackage);
168
169 /// Starts a Thread, not based on a starting Message. \brief Starts a Thread, not based on a starting Message.
170 /// \param dataPackage A StartThreadWithoutMessageData structure.
171 /// \returns A CoRoutine containing a Channel.
172 static CoRoutine<Thread> startThreadWithoutMessageAsync(StartThreadWithoutMessageData dataPackage);
173
174 /// Starts a Thread, in a forum channel. \brief Starts a Thread, in a forum channel.
175 /// \param dataPackage A StartThreadInForumChannelData structure.
176 /// \returns A CoRoutine containing a Channel.
177 static CoRoutine<Thread> startThreadInForumChannelAsync(StartThreadInForumChannelData dataPackage);
178
179 /// Joins a Thread. \brief Joins a Thread.
180 /// \param dataPackage A JoinThreadData structure.
181 /// \returns A CoRoutine containing void.
182 static CoRoutine<void> joinThreadAsync(JoinThreadData dataPackage);
183
184 /// Adds a new User to a chosen Thread. \brief Adds a new User to a chosen Thread.
185 /// \param dataPackage An AddThreadMemberData structure.
186 /// \returns A CoRoutine containing void.
187 static CoRoutine<void> addThreadMemberAsync(AddThreadMemberData dataPackage);
188
189 /// Leaves a Thread. \brief Leaves a Thread.
190 /// \param dataPackage A LeaveThreadData structure.
191 /// \returns A CoRoutine containing void.
192 static CoRoutine<void> leaveThreadAsync(LeaveThreadData dataPackage);
193
194 /// Removes a User from a chosen Thread. \brief Removes a User from a chosen Thread.
195 /// \param dataPackage A RemoveThreadMemberData structure.
196 /// \returns A CoRoutine containing void.
197 static CoRoutine<void> removeThreadMemberAsync(RemoveThreadMemberData dataPackage);
198
199 /// Collects a ThreadMember if they exist. \brief Collects a ThreadMember if they exist.
200 /// \param dataPackage A GetThreadMemberData structure.
201 /// \returns A CoRoutine containing a ThreadMemberData.
202 static CoRoutine<ThreadMemberData> getThreadMemberAsync(GetThreadMemberData dataPackage);
203
204 /// Collects a list of ThreadMembers if they exist. \brief Collects a list of ThreadMembers if they exist.
205 /// \param dataPackage A GetThreadMembersData structure.
206 /// returns A CoRoutine containing a vector<ThreadMemberData>.
207 static CoRoutine<std::vector<ThreadMemberData>> getThreadMembersAsync(GetThreadMembersData dataPackage);
208
209 /// Collects a list of Threads from a given Channel. \brief Collects a list of Threads from a given Channel.
210 /// \param dataPackage A GetActiveThreadsData structure.
211 /// \returns A CoRoutine containing a ActiveThreadsData.
212 static CoRoutine<ActiveThreadsData> getActiveThreadsAsync(GetActiveThreadsData dataPackage);
213
214 /// Collects a list of public archived Threads from a given Channel. \brief Collects a list of public archived Threads from a given Channel.
215 /// \param dataPackage A GetPublicArchivedThreadsData structure.
216 /// \returns A CoRoutine containing a ArchivedThreadsData.
217 static CoRoutine<ArchivedThreadsData> getPublicArchivedThreadsAsync(GetPublicArchivedThreadsData dataPackage);
218
219 /// Collects a list of private archived Threads from a given Channel. \brief Collects a list of private archived Threads from a given Channel.
220 /// \param dataPackage A GetPrivateArchivedThreadsData structure.
221 /// \returns A CoRoutine containing a ArchivedThreadsData.
222 static CoRoutine<ArchivedThreadsData> getPrivateArchivedThreadsAsync(GetPrivateArchivedThreadsData dataPackage);
223
224 /// Collects a list of joined private archived Threads from a given Channel. \brief Collects a list of joined private archived Threads from a given Channel.
225 /// \param dataPackage A GetPrivateArchivedThreadsData structure.
226 /// \returns A CoRoutine containing a ArchivedThreadsData.
227 static CoRoutine<ArchivedThreadsData> getJoinedPrivateArchivedThreadsAsync(GetJoinedPrivateArchivedThreadsData dataPackage);
228
229 /// Lists all of the active Threads of a chosen Guild. \brief Lists all of the active Threads of a chosen Guild.
230 /// \param dataPackage A ListActiveThreadsData structure.
231 /// \returns A CoRoutine containing a vector<Channel>.
232 static CoRoutine<ActiveThreadsData> getActiveGuildThreadsAsync(GetActiveGuildThreadsData dataPackage);
233
234 protected:
235 static DiscordCoreInternal::HttpsClient* httpsClient;
236 };
237 /**@}*/
238};// namespace DiscordCoreAPI
239#endif
ThreadType
Thread types.
ThreadAutoArchiveDuration
Automatic Thread archiving durations.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:62
Represents a forum thread message.
For starting a Thread, based on a Message.
For starting a Thread, not based on a Message.
For starting a Thread, in a forum channel.
For adding a chosen User to a chosen Thread.
For removing a chosen User from a Thread.
For collecting a ThreadMember responseData structure for a given ThreadMember.
For collecting the list of ThreadMembers from a Thread.
For collecting the list of active Threads.
For collecting puiblic archived Threads from a given Channel.
For collecting private archived Threads from a given Channel.
For collecting joined private archived Threads from a given Channel.
For listing the active Threads in a chosen Guild.
Represents a single Thread.
An interface class for the Thread related endpoints.