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 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/// ChannelEntities.hpp - Header for the classes related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file ChannelEntities.hpp
30#pragma once
31
34
35namespace discord_core_api {
36
37 /**
38 * \addtogroup foundation_entities
39 * @{
40 */
41
42 /// @brief For collecting a channel from discord's servers.
44 snowflake channelId{};///< The id of the channel_data to acquire.
45 };
46
47 /// @brief For deleting or closing a channel.
49 snowflake channelId{};///< The id of the channel_data to close/delete.
50 jsonifier::string reason{};///< The reason for deleting/closing the channel_data.
51 };
52
53 /// @brief For editing the permission_types overwrites of a given channel, for a given role or user_data.
55 permission_overwrites_type type{};///< The type of overwrite.
56 snowflake roleOrUserId{};///< The role_data or user_data snowflake to modify the permissions for.
57 snowflake channelId{};///< The channel_data id of the desired channel_data to modify the permissions for.
58 jsonifier::string reason{};///< Reason for editing the permission overwrites.
59 permissions_parse allow{};///< The permissions to list as "allowed".
60 permissions_parse deny{};///< The permissions to list as "deny".
61 };
62
63 /// @brief For collecting the invites to a given channel.
65 snowflake channelId{};
66 };
67
68 /// @brief For creating an invite to a given channel.
70 snowflake targetApplicationId{};///< The id of the embedded application to open for this invite, required if target_type is 2.
71 invite_target_types targetType{};///< the type of target for this voice channel_data invite.
72 snowflake targetUserId{};///< snowflake of the user whose stream to display for this invite, required if target_type is 1.
73 snowflake channelId{};///< The id of the channel_data to create the invite for.
74 jsonifier::string reason{};///< Reason for creating the invite.
75 int32_t maxUses{};///< Max number of uses or 0 for unlimited.between 0 and 100.
76 int32_t maxAge{};///< Duration of invite in seconds before expiry, or 0 for never.between 0 and 604800 (7 days) 86400 (24 hours).
77 bool temporary{};///< Whether this invite only grants temporary membership.
78 bool unique{};///< If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).
79 };
80
81 /// @brief For deleting the permission_types overwrites of a given channel for a given role or user_data.
83 snowflake roleOrUserId{};///< The role_data or user_data id for whom to delete the permission_types overwrites.
84 snowflake channelId{};///< The id of the channel_data to modify permissions for.
85 jsonifier::string reason{};///< Reason for deleting these permission overwrites.
86 };
87
88 /// @brief For following a news channel_data.
90 snowflake targetChannelId{};
91 snowflake channelId{};
92 };
93
94 /// @brief For triggering the typing indicator in a given channel.
96 snowflake channelId{};
97 };
98
99 /// @brief For acquiring a list of channels from a chosen guild_data.
101 snowflake guildId{};///< The guild_data from which to collect the channels from.
102 };
103
104 /// @brief For creating a new channel_data within a chosen guild_data.
106 jsonifier::vector<over_write_data> permissionOverwrites{};///< Array of overwrite objects the channel_data's permission overwrites.
107 int32_t defaultAutoArchiveDuration{};///< Defualt duration of time before archiving a thread.
108 int32_t rateLimitPerUser{};///< Amount of seconds a user has to wait before sending another message(0 - 21600).
109 jsonifier::string reason{};///< Reason for creating the channel_data.
110 snowflake parentId{};///< snowflake of the parent category for a channel.
111 jsonifier::string topic{};///< channel_data topic(0 - 1024 characters).
112 int32_t userLimit{};///< The user limit of the voice channel_data(voice only).
113 snowflake guildId{};///< The guild_data within which to create the channel_data.
114 int32_t position{};///< Sorting position of the channel_data.
115 jsonifier::string name{};///< The name of the channel_data.
116 channel_type type{};///< The type of channel_data.
117 int32_t bitrate{};///< The bitrate(in bits) of the voice channel_data(voice only).
118 bool nsfw{};///< whether the channel_data is nsfw.
119 };
120
121 /// @brief For modifying the channel_data position responseData of a single channel_data.
123 bool lockPermissions{};///< Syncs the permission overwrites with the new parent, if moving to a new category.
124 snowflake parentId{};///< The new parent id for the channel_data that is moved.
125 int32_t position{};///< Sorting position of the channel_data.
126 snowflake id{};///< channel_data id.
127 };
128
129 /// @brief For modifying the current positions of one or more channels in the guild_data.
131 jsonifier::vector<modify_guild_channel_position_data> modifyChannelData{};///< Array of new channel_data position's responseData.
132 jsonifier::string reason{};///< Reason for re-ordering the channel_data positions.
133 snowflake guildId{};///< Guild within which to re-order the channel_data positions.
134 };
135
136 /// @brief For collecting a direct-messaging channel_data.
138 snowflake userId{};///< The user_data for whom to collect the direct-messaging channel_data to.
139 };
140
141 /// @brief For modifying a channel's properties.
142 struct DiscordCoreAPI_Dll modify_channel_data {
143 update_channel_data channelData{};///< The responseData of the channel_data to be updated.
144 snowflake channelId{};///< The id of the channel_data to modify.
145 jsonifier::string reason{};///< A reason for modifying the channel_data.
146
147 modify_channel_data(channel_data newData);
148 };
149
150 /**@}*/
151
152 /**
153 * \addtogroup main_endpoints
154 * @{
155 */
156 /// @brief An interface class for the channel_data related endpoints.
157 class DiscordCoreAPI_Dll channels {
158 public:
159 friend class discord_core_internal::websocket_client;
160 friend class discord_core_client;
161 friend class channel_data;
162 friend class guild_data;
163 friend class guild_data;
164
165 static void initialize(discord_core_internal::https_client*, config_manager* configManager);
166
167 /// @brief Collects a channel from the discord servers.
168 /// @param dataPackage a get_channel_data structure.
169 /// @return a co_routine containing a channel.
170 static co_routine<channel_data> getChannelAsync(get_channel_data dataPackage);
171
172 /// @brief Collects a channel from the library's cache.
173 /// @param dataPackage a get_channel_data structure.
174 /// @return a co_routine containing a channel.
175 static channel_cache_data getCachedChannel(get_channel_data dataPackage);
176
177 /// @brief Modifies a channel's properties.
178 /// @param dataPackage a modify_channel_data structure.
179 /// @return a co_routine containing a channel.
180 static co_routine<channel_data> modifyChannelAsync(modify_channel_data dataPackage);
181
182 /// @brief Delete a channel, or close a protected message.
183 /// @param dataPackage a delete_or_close_channel_data structure.
184 /// @return a co_routine containing a channel.
185 static co_routine<void> deleteOrCloseChannelAsync(delete_or_close_channel_data dataPackage);
186
187 /// @brief Edit the given jsonifier::string overwrites for a given user or role_data.
188 /// @param dataPackage an edit_channel_permission_overwrites_data structure.
189 /// @return a co_routine containing void.
190 static co_routine<void> editChannelPermissionOverwritesAsync(edit_channel_permission_overwrites_data dataPackage);
191
192 /// @brief Collects a vector of the invites to a given channel.
193 /// @param dataPackage a get_channel_invites_data structure.
194 /// @return a co_routine containing a jsonifier::vector<invite_data>.
195 static co_routine<jsonifier::vector<invite_data>> getChannelInvitesAsync(get_channel_invites_data dataPackage);
196
197 /// @brief Creates an invite to a selected channel_data.
198 /// @param dataPackage a create_channel_invite_data structure.
199 /// @return a co_routine containing an invite_data.
200 static co_routine<invite_data> createChannelInviteAsync(create_channel_invite_data dataPackage);
201
202 /// @brief Delete the given jsonifier::string overwrites for a given user or role_data.
203 /// @param dataPackage a delete_channel_permission_overwrites_data structure
204 /// @return a co_routine containing void.
205 static co_routine<void> deleteChannelPermissionOverwritesAsync(delete_channel_permission_overwrites_data dataPackage);
206
207 /// @brief Follows a given new channel_data with another channel_data.
208 /// @param dataPackage a follow_news_channel_data structure.
209 /// @return a co_routine containing a channel.
210 static co_routine<channel_data> followNewsChannelAsync(follow_news_channel_data dataPackage);
211
212 /// @brief Triggers the typing indicator for the bot in the given channel.
213 /// @param dataPackage a trigger_typing_indicator_data structure.
214 /// @return a co_routine containing void.
215 static co_routine<void> triggerTypingIndicatorAsync(trigger_typing_indicator_data dataPackage);
216
217 /// @brief Collects a list of channels from a chosen guild_data.
218 /// @param dataPackage a get_guild_channels_data structure.
219 /// @return a co_routine containing a jsonifier::vector<channel_data>.
220 static co_routine<jsonifier::vector<channel_data>> getGuildChannelsAsync(get_guild_channels_data dataPackage);
221
222 /// @brief Creates a new channel_data within a chosen guild_data.
223 /// @param dataPackage a create_guild_channel_data structure.
224 /// @return a co_routine containing a channel.
225 static co_routine<channel_data> createGuildChannelAsync(create_guild_channel_data dataPackage);
226
227 /// @brief Re-orders the channel_data positions, within a chosen guild_data.
228 /// @param dataPackage a modify_guild_channel_positions_data structure.
229 /// @return a co_routine containing void.
230 static co_routine<void> modifyGuildChannelPositionsAsync(modify_guild_channel_positions_data dataPackage);
231
232 /// @brief Collect a direct-message_data channel between the bot and the user_data.
233 /// @param dataPackage a create_dmchannel_data structure.
234 /// @return a co_routine containing a channel.
235 static co_routine<channel_data> createDMChannelAsync(create_dmchannel_data dataPackage);
236
237 /// @brief Collect a list of voice regions that are usable for the rtc-region option of a given channel.
238 /// @return a co_routine containing a voice_region_data_vector.
239 static co_routine<jsonifier::vector<voice_region_data>> getVoiceRegionsAsync();
240
241 template<typename channel_type> DCA_INLINE static void insertChannel(channel_type&& channel) {
242 if (doWeCacheChannelsBool) {
243 if (channel.id == 0) {
244 throw dca_exception{ "Sorry, but there was no id set for that channel." };
245 }
246 cache.emplace(std::forward<channel_type>(channel));
247 if (cache.count() % 1000 == 0) {
248 std::cout << "current channel count: " << cache.count() << std::endl;
249 }
250 }
251 }
252
253 static void removeChannel(const channel_cache_data& channelId);
254
255 static bool doWeCacheChannels();
256
257 protected:
258 static object_cache<channel_cache_data> cache;
259 static discord_core_internal::https_client* httpsClient;
260 static bool doWeCacheChannelsBool;
261 };
262 /**@}*/
263}
An interface class for the channel_data related endpoints.
channel_type
Channel_data types.
permission_overwrites_type
Permission_types overwrites types.
invite_target_types
Invite target types.
The main namespace for the forward-facing interfaces.
For creating an invite to a given channel.
bool unique
If true, don't try to reuse a similar invite (useful for creating many unique one time use invites).
int32_t maxUses
Max number of uses or 0 for unlimited.between 0 and 100.
snowflake targetApplicationId
The id of the embedded application to open for this invite, required if target_type is 2.
invite_target_types targetType
the type of target for this voice channel_data invite.
int32_t maxAge
Duration of invite in seconds before expiry, or 0 for never.between 0 and 604800 (7 days) 86400 (24 h...
snowflake channelId
The id of the channel_data to create the invite for.
jsonifier::string reason
Reason for creating the invite.
bool temporary
Whether this invite only grants temporary membership.
snowflake targetUserId
snowflake of the user whose stream to display for this invite, required if target_type is 1.
For collecting a direct-messaging channel_data.
snowflake userId
The user_data for whom to collect the direct-messaging channel_data to.
For creating a new channel_data within a chosen guild_data.
jsonifier::vector< over_write_data > permissionOverwrites
Array of overwrite objects the channel_data's permission overwrites.
int32_t defaultAutoArchiveDuration
Defualt duration of time before archiving a thread.
jsonifier::string reason
Reason for creating the channel_data.
int32_t position
Sorting position of the channel_data.
int32_t rateLimitPerUser
Amount of seconds a user has to wait before sending another message(0 - 21600).
snowflake parentId
snowflake of the parent category for a channel.
jsonifier::string topic
channel_data topic(0 - 1024 characters).
jsonifier::string name
The name of the channel_data.
snowflake guildId
The guild_data within which to create the channel_data.
channel_type type
The type of channel_data.
int32_t bitrate
The bitrate(in bits) of the voice channel_data(voice only).
bool nsfw
whether the channel_data is nsfw.
int32_t userLimit
The user limit of the voice channel_data(voice only).
For deleting the permission_types overwrites of a given channel for a given role or user_data.
jsonifier::string reason
Reason for deleting these permission overwrites.
snowflake roleOrUserId
The role_data or user_data id for whom to delete the permission_types overwrites.
snowflake channelId
The id of the channel_data to modify permissions for.
snowflake channelId
The id of the channel_data to close/delete.
jsonifier::string reason
The reason for deleting/closing the channel_data.
For editing the permission_types overwrites of a given channel, for a given role or user_data.
permissions_parse deny
The permissions to list as "deny".
permissions_parse allow
The permissions to list as "allowed".
snowflake roleOrUserId
The role_data or user_data snowflake to modify the permissions for.
permission_overwrites_type type
The type of overwrite.
jsonifier::string reason
Reason for editing the permission overwrites.
snowflake channelId
The channel_data id of the desired channel_data to modify the permissions for.
For following a news channel_data.
For collecting a channel from discord's servers.
snowflake channelId
The id of the channel_data to acquire.
For collecting the invites to a given channel.
For acquiring a list of channels from a chosen guild_data.
snowflake guildId
The guild_data from which to collect the channels from.
For modifying a channel's properties.
For modifying the channel_data position responseData of a single channel_data.
int32_t position
Sorting position of the channel_data.
bool lockPermissions
Syncs the permission overwrites with the new parent, if moving to a new category.
snowflake parentId
The new parent id for the channel_data that is moved.
For modifying the current positions of one or more channels in the guild_data.
jsonifier::string reason
Reason for re-ordering the channel_data positions.
jsonifier::vector< modify_guild_channel_position_data > modifyChannelData
Array of new channel_data position's responseData.
snowflake guildId
Guild within which to re-order the channel_data positions.
For triggering the typing indicator in a given channel.