DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
ChannelEntities.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/// ChannelEntities.hpp - Header for the classes related classes and structs.
22/// May 13, 2021
23/// https://discordcoreapi.com
24/// \file ChannelEntities.hpp
25
26#pragma once
27
30
31namespace DiscordCoreAPI {
32
33 DiscordCoreAPI_Dll inline bool operator==(const ChannelData& lhs, const ChannelData& rhs) {
34 return lhs.id == rhs.id;
35 }
36
37 /**
38 * \addtogroup foundation_entities
39 * @{
40 */
41
42 /// \brief For collecting a Channel from Discord's servers.
43 struct DiscordCoreAPI_Dll GetChannelData {
44 Snowflake channelId{};///< The id of the Channel to acquire.
45 };
46
47 /// \brief For deleting or closing a Channel.
48 struct DiscordCoreAPI_Dll DeleteOrCloseChannelData {
49 Snowflake channelId{};///< The id of the Channel to close/delete.
50 std::string reason{};///< The reason for deleting/closing the Channel.
51 };
52
53 /// \brief For editing the PermissionTypes overwrites of a given Channel, for a given Role or User.
54 struct DiscordCoreAPI_Dll EditChannelPermissionOverwritesData {
55 PermissionOverwritesType type{};///< The type of overwrite.
56 Snowflake roleOrUserId{};///< The Role or User Id to modify the permissions for.
57 Snowflake channelId{};///< The Channel id of the desired Channel to modify the permissions for.
58 std::string reason{};///< Reason for editing the permission overwrites.
59 std::string allow{};///< The permissions to list as "allowed".
60 std::string deny{};///< The permissions to list as "deny".
61
62 operator Jsonifier();
63 };
64
65 /// \brief For collecting the invites to a given Channel.
66 struct DiscordCoreAPI_Dll GetChannelInvitesData {
67 Snowflake channelId{};
68 };
69
70 /// \brief For creating an invite to a given Channel.
71 struct DiscordCoreAPI_Dll CreateChannelInviteData {
72 Snowflake targetApplicationId{};///< The id of the embedded application to open for this invite, required if target_type is 2.
73 InviteTargetTypes targetType{};///< The type of target for this voice Channel invite.
74 Snowflake targetUserId{};///< Id of the user whose stream to display for this invite, required if target_type is 1.
75 Snowflake channelId{};///< The id of the Channel to create the invite for.
76 std::string reason{};///< Reason for creating the invite.
77 int32_t maxUses{};///< Max number of uses or 0 for unlimited.between 0 and 100.
78 int32_t maxAge{};///< Duration of invite in seconds before expiry, or 0 for never.between 0 and 604800 (7 days) 86400 (24 hours).
79 bool temporary{};///< Whether this invite only grants temporary membership.
80 bool unique{};///< If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).
81
82 operator Jsonifier();
83 };
84
85 /// \brief For deleting the PermissionTypes overwrites of a given Channel for a given Role or User.
86 struct DiscordCoreAPI_Dll DeleteChannelPermissionOverwritesData {
87 Snowflake roleOrUserId{};///< The Role or User id for whom to delete the PermissionTypes overwrites.
88 Snowflake channelId{};///< The id of the Channel to modify permissions for.
89 std::string reason{};///< Reason for deleting these permission overwrites.
90 };
91
92 /// \brief For following a news Channel.
93 struct DiscordCoreAPI_Dll FollowNewsChannelData {
94 Snowflake targetChannelId{};
95 Snowflake channelId{};
96
97 operator Jsonifier();
98 };
99
100 /// \brief For triggering the typing indicator in a given Channel.
101 struct DiscordCoreAPI_Dll TriggerTypingIndicatorData {
102 Snowflake channelId{};
103 };
104
105 /// \brief For acquiring a list of Channels from a chosen Guild.
106 struct DiscordCoreAPI_Dll GetGuildChannelsData {
107 Snowflake guildId{};///< The Guild from which to collect the Channels from.
108 };
109
110 /// \brief For creating a new Channel within a chosen Guild.
111 struct DiscordCoreAPI_Dll CreateGuildChannelData {
112 std::vector<OverWriteData> permissionOverwrites{};///< Array of overwrite objects the Channel's permission overwrites.
113 int32_t defaultAutoArchiveDuration{};///< Defualt duration of time before archiving a thread.
114 int32_t rateLimitPerUser{};///< Amount of seconds a user has to wait before sending another message(0 - 21600).
115 std::string reason{};///< Reason for creating the Channel.
116 Snowflake parentId{};///< Id of the parent category for a Channel.
117 std::string topic{};///< Channel topic(0 - 1024 characters).
118 int32_t userLimit{};///< The user limit of the voice Channel(voice only).
119 Snowflake guildId{};///< The Guild within which to create the Channel.
120 int32_t position{};///< Sorting position of the Channel.
121 std::string name{};///< The name of the Channel.
122 ChannelType type{};///< The type of Channel.
123 int32_t bitrate{};///< The bitrate(in bits) of the voice Channel(voice only).
124 bool nsfw{};///< Whether the Channel is nsfw.
125
126 operator Jsonifier();
127 };
128
129 /// \brief For modifying the Channel position responseData of a single Channel.
130 struct DiscordCoreAPI_Dll ModifyGuildChannelPositionData {
131 bool lockPermissions{};///< Syncs the permission overwrites with the new parent, if moving to a new category.
132 Snowflake parentId{};///< The new parent ID for the Channel that is moved.
133 int32_t position{};///< Sorting position of the Channel.
134 Snowflake id{};///< Channel id.
135 };
136
137 /// \brief For modifying the current positions of one or more Channels in the Guild.
138 struct DiscordCoreAPI_Dll ModifyGuildChannelPositionsData {
139 std::vector<ModifyGuildChannelPositionData> modifyChannelData{};///< Array of new Channel position's responseData.
140 std::string reason{};///< Reason for re-ordering the Channel positions.
141 Snowflake guildId{};///< Guild within which to re-order the Channel positions.
142
143 operator Jsonifier();
144 };
145
146 /// \brief For collecting a direct-messaging Channel.
147 struct DiscordCoreAPI_Dll CreateDMChannelData {
148 Snowflake userId{};///< The User for whom to collect the direct-messaging Channel to.
149 };
150
151 /// \brief A Channel object.
152 class DiscordCoreAPI_Dll Channel : public ChannelData {
153 public:
154 std::unordered_map<uint64_t, UserData> recipients{};///< Recipients, in the case of a group DM or m.
155 DefaultReactionData defaultReactionEmoji{};///< The emoji to show in the add reaction button on a thread in a GUILD_FORUM channel.
156 std::vector<ForumTagData> availableTags{};///< The set of tags that can be used in a GUILD_FORUM channel.
157 int32_t defaultThreadRateLimitPerUser{};///< The initial rate_limit_per_user to set on newly created threads in a channel.
158 int32_t defaultAutoArchiveDuration{};///< Default time it takes to archive a thread.
159 std::vector<Snowflake> appliedTags{};///< The IDs of the set of tags that have been applied to a thread in a GUILD_FORUM channel.
160 ThreadMetadataData threadMetadata{};///< Metadata in the case that this Channel is a Thread.
161 StringWrapper lastMessageId{};///< Id of the last Message.
162 TimeStamp lastPinTimestamp{};///< Timestamp of the last pinned Message.
163 StringWrapper permissions{};///< Computed permissions for the invoking user in the channel, including overwrites.
164 int32_t videoQualityMode{};///< Video quality mode.
165 int32_t rateLimitPerUser{};///< Amount of seconds a User has to wait before sending another Message.
166 int32_t totalMessageSent{};///< Number of messages ever sent in a thread it's similar to message_count on message creation.
167 Snowflake applicationId{};///< Application id of the current application.
168 StringWrapper rtcRegion{};///< Real-time clock region.
169 ThreadMemberData member{};///< Thread member object for the current User, if they have joined the Thread.
170 int32_t messageCount{};///< An approximate count of Messages in a Thread stops counting at 50.
171 StringWrapper topic{};///< The Channel's topic.
172 int32_t userLimit{};///< User limit, in the case of voice channels.
173 int32_t bitrate{};///< Bitrate of the Channel, if it is a voice Channel.
174 IconHash icon{};///< Icon for the Channel, if applicable.
175
176 Channel() noexcept = default;
177
178 Channel& operator=(ChannelData&&) noexcept;
179
180 Channel(ChannelData&&) noexcept;
181
182 Channel& operator=(const ChannelData&) noexcept;
183
184 Channel(const ChannelData&) noexcept;
185
186 Channel(simdjson::ondemand::value jsonObjectData);
187
188 ~Channel() noexcept = default;
189
190 std::string getIconUrl() noexcept;
191 };
192
193 class DiscordCoreAPI_Dll ChannelVector {
194 public:
195 ChannelVector() noexcept = default;
196
197 operator std::vector<Channel>();
198
199 ChannelVector(simdjson::ondemand::value jsonObjectData);
200
201 virtual ~ChannelVector() noexcept = default;
202
203 protected:
204 std::vector<Channel> channels{};
205 };
206
207 /// \brief For modifying a Channel's properties.
208 struct DiscordCoreAPI_Dll ModifyChannelData {
209 UpdateChannelData channelData{};///< The responseData of the Channel to be updated.
210 Snowflake channelId{};///< The id of the Channel to modify.
211 std::string reason{};///< A reason for modifying the Channel.
212
213 operator Jsonifier();
214
215 ModifyChannelData(Channel newData);
216 };
217
218 /**@}*/
219
220 /**
221 * \addtogroup main_endpoints
222 * @{
223 */
224 /// \brief An interface class for the Channel-related endpoints.
225 class DiscordCoreAPI_Dll Channels {
226 public:
227 friend class DiscordCoreInternal::WebSocketClient;
228 friend class DiscordCoreClient;
229 friend class ChannelData;
230 friend class GuildData;
231 friend class Guild;
232
233 static void initialize(DiscordCoreInternal::HttpsClient*, ConfigManager* configManager);
234
235 /// \brief Collects a Channel from the Discord servers.
236 /// \param dataPackage A GetChannelData structure.
237 /// \returns A CoRoutine containing a Channel.
238 static CoRoutine<Channel> getChannelAsync(GetChannelData dataPackage);
239
240 /// \brief Collects a Channel from the library's cache.
241 /// \param dataPackage A GetChannelData structure.
242 /// \returns A CoRoutine containing a Channel.
243 static ChannelData getCachedChannel(GetChannelData dataPackage);
244
245 /// \brief Modifies a Channel's properties.
246 /// \param dataPackage A ModifyChannelData structure.
247 /// \returns A CoRoutine containing a Channel.
248 static CoRoutine<Channel> modifyChannelAsync(ModifyChannelData dataPackage);
249
250 /// \brief Delete a Channel, or close a private message.
251 /// \param dataPackage A DeleteOrCloseChannelData structure.
252 /// \returns A CoRoutine containing a Channel.
253 static CoRoutine<void> deleteOrCloseChannelAsync(DeleteOrCloseChannelData dataPackage);
254
255 /// \brief Edit the given Permissions overwrites for a given User or Role.
256 /// \param dataPackage An EditChannelPermissionOverwritesData structure.
257 /// \returns A CoRoutine containing void.
258 static CoRoutine<void> editChannelPermissionOverwritesAsync(EditChannelPermissionOverwritesData dataPackage);
259
260 /// \brief Collects a vector of the invites to a given Channel.
261 /// \param dataPackage A GetChannelInvitesData structure.
262 /// \returns A CoRoutine containing a InviteDataVector.
263 static CoRoutine<std::vector<InviteData>> getChannelInvitesAsync(GetChannelInvitesData dataPackage);
264
265 /// \brief Creates an invite to a selected Channel.
266 /// \param dataPackage A CreateChannelInviteData structure.
267 /// \returns A CoRoutine containing an InviteData.
268 static CoRoutine<InviteData> createChannelInviteAsync(CreateChannelInviteData dataPackage);
269
270 /// \brief Delete the given Permissions overwrites for a given User or Role.
271 /// \param dataPackage A DeleteChannelPermissionOverwritesData structure
272 /// \returns A CoRoutine containing void.
273 static CoRoutine<void> deleteChannelPermissionOverwritesAsync(DeleteChannelPermissionOverwritesData dataPackage);
274
275 /// \brief Follows a given new Channel with another Channel.
276 /// \param dataPackage A FollowNewsChannelData structure.
277 /// \returns A CoRoutine containing a Channel.
278 static CoRoutine<Channel> followNewsChannelAsync(FollowNewsChannelData dataPackage);
279
280 /// \brief Triggers the typing indicator for the bot in the given Channel.
281 /// \param dataPackage A TriggerTypingIndicatorData structure.
282 /// \returns A CoRoutine containing void.
283 static CoRoutine<void> triggerTypingIndicatorAsync(TriggerTypingIndicatorData dataPackage);
284
285 /// \brief Collects a list of Channels from a chosen Guild.
286 /// \param dataPackage A GetGuildChannelsData structure.
287 /// \returns A CoRoutine containing a ChannelVector.
288 static CoRoutine<std::vector<Channel>> getGuildChannelsAsync(GetGuildChannelsData dataPackage);
289
290 /// \brief Creates a new Channel within a chosen Guild.
291 /// \param dataPackage A CreateGuildChannelData structure.
292 /// \returns A CoRoutine containing a Channel.
293 static CoRoutine<Channel> createGuildChannelAsync(CreateGuildChannelData dataPackage);
294
295 /// \brief Re-orders the Channel positions, within a chosen Guild.
296 /// \param dataPackage A ModifyGuildChannelPositionsData structure.
297 /// \returns A CoRoutine containing void.
298 static CoRoutine<void> modifyGuildChannelPositionsAsync(ModifyGuildChannelPositionsData dataPackage);
299
300 /// \brief Collect a direct-Message Channel between the bot and the User.
301 /// \param dataPackage A CreateDMChannelData structure.
302 /// \returns A CoRoutine containing a Channel.
303 static CoRoutine<Channel> createDMChannelAsync(CreateDMChannelData dataPackage);
304
305 /// \brief Collect a list of voice regions that are usable for the RTC-Region option of a given Channel.
306 /// \returns A CoRoutine containing a VoiceRegionDataVector.
307 static CoRoutine<std::vector<VoiceRegionData>> getVoiceRegionsAsync();
308
309 static void insertChannel(ChannelData channel);
310
311 static void removeChannel(Snowflake channelId);
312
313 static bool doWeCacheChannels();
314
315 protected:
316 static DiscordCoreInternal::HttpsClient* httpsClient;
317 static ObjectCache<ChannelData> cache;
318 static bool doWeCacheChannelsBool;
319 };
320 /**@}*/
321}// namespace DiscordCoreAPI
InviteTargetTypes
Invite target types.
ChannelType
Channel types.
PermissionOverwritesType
PermissionTypes overwrites types.
The main namespace for this library.
For collecting a Channel from Discord's servers.
For deleting or closing a Channel.
For editing the PermissionTypes overwrites of a given Channel, for a given Role or User.
For collecting the invites to a given Channel.
For creating an invite to a given Channel.
For deleting the PermissionTypes overwrites of a given Channel for a given Role or User.
For following a news Channel.
For triggering the typing indicator in a given Channel.
For acquiring a list of Channels from a chosen Guild.
For creating a new Channel within a chosen Guild.
For modifying the Channel position responseData of a single Channel.
For modifying the current positions of one or more Channels in the Guild.
For collecting a direct-messaging Channel.
For modifying a Channel's properties.
An interface class for the Channel-related endpoints.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:59
DiscordCoreClient - The main class for this library.
Meta data for a Thread type of Channel.
Data for a single member of a Thread.
Data structure representing a single Channel.
For updating/modifying a given Channel's properties.
Data structure representing a single Guild.
A discord Guild. Used to connect to/disconnect from voice.
Class for representing a timeStamp, as well as working with time-related values.
Definition: Utilities.hpp:1576