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