37 template<>
struct core<DiscordCoreAPI::EditChannelPermissionOverwritesData> {
39 static constexpr auto parseValue = objectVal(
"allow", &ValueType::allow,
"deny", &ValueType::deny,
"channel_id", &ValueType::channelId,
"reason", &ValueType::reason,
40 "type", &ValueType::type,
"id", &ValueType::roleOrUserId);
43 template<>
struct core<DiscordCoreAPI::CreateChannelInviteData> {
45 static constexpr auto parseValue = objectVal(
"channel_id", &ValueType::channelId,
"max_uses", &ValueType::maxUses,
"max_age", &ValueType::maxAge,
"temporary",
46 &ValueType::temporary,
"unique", &ValueType::unique,
"target_type", &ValueType::targetType,
"target_user_id", &ValueType::targetUserId,
"target_application_id",
47 &ValueType::targetApplicationId,
"reason", &ValueType::reason);
50 template<>
struct core<DiscordCoreAPI::CreateGuildChannelData> {
52 static constexpr auto parseValue = objectVal(
"name", &ValueType::name,
"type", &ValueType::type,
"position", &ValueType::position,
"parent_id", &ValueType::parentId,
53 "permission_overwrites", &ValueType::permissionOverwrites,
"nsfw", &ValueType::nsfw,
"rate_limit_per_user", &ValueType::rateLimitPerUser,
"topic", &ValueType::topic,
54 "user_limit", &ValueType::userLimit,
"bitrate", &ValueType::bitrate,
"default_auto_archive_duration", &ValueType::defaultAutoArchiveDuration,
"guild_id",
55 &ValueType::guildId,
"reason", &ValueType::reason);
58 template<>
struct core<DiscordCoreAPI::ModifyGuildChannelPositionData> {
60 static constexpr auto parseValue =
61 objectVal(
"id", &ValueType::id,
"position", &ValueType::position,
"parent_id", &ValueType::parentId,
"lock_permissions", &ValueType::lockPermissions);
64 template<>
struct core<DiscordCoreAPI::ModifyGuildChannelPositionsData> {
66 static constexpr auto parseValue = arrayVal(&ValueType::modifyChannelData);
69 template<>
struct core<DiscordCoreAPI::ModifyChannelData> {
71 static constexpr auto parseValue = objectVal(
"channel_id", &ValueType::channelId,
"channel_data", &ValueType::channelData,
"reason", &ValueType::reason);
74 template<>
struct core<DiscordCoreAPI::CreateDMChannelData> {
76 static constexpr auto parseValue = objectVal(
"user_id", &ValueType::userId);
79 template<>
struct core<DiscordCoreAPI::FollowNewsChannelData> {
81 static constexpr auto parseValue = objectVal(
"channel_id", &ValueType::channelId,
"target_channel_id", &ValueType::targetChannelId);
84 template<>
struct core<DiscordCoreAPI::UpdateChannelData> {
86 static constexpr auto parseValue = objectVal(
"permission_overwrites", &ValueType::permissionOverwrites,
"default_auto_archive_duration",
87 &ValueType::defaultAutoArchiveDuration,
"video_quality_mode", &ValueType::videoQualityMode,
"rate_limit_per_user", &ValueType::rateLimitPerUser,
"bitrate",
88 &ValueType::bitrate,
"parent_id", &ValueType::parentId,
"rtc_region", &ValueType::rtcRgion,
"user_limit", &ValueType::userLimit,
"topic", &ValueType::topic,
"position",
89 &ValueType::position,
"type", &ValueType::type,
"name", &ValueType::name,
"nsfw", &ValueType::nsfw);
93namespace DiscordCoreAPI {
95 ChannelData::ChannelData(Snowflake newId) {
99 ChannelCacheData& ChannelCacheData::operator=(
const ChannelData& other) {
100 if (other.permissionOverwrites.size() > 0) {
103 setFlagValue(ChannelFlags::Managed, other.managed);
104 setFlagValue(ChannelFlags::NSFW, other.nsfw);
105 if (
static_cast<int64_t
>(other.flags) != 0) {
108 if (other.memberCount != 0) {
111 if (other.parentId != 0) {
114 if (other.position != 0) {
117 if (other.guildId != 0) {
120 if (other.ownerId != 0) {
123 if (other.topic !=
"") {
126 if (other.name !=
"") {
136 ChannelCacheData::ChannelCacheData(
const ChannelData& other) {
140 ChannelCacheData& ChannelCacheData::operator=(ChannelData&& other) {
141 if (other.permissionOverwrites.size() > 0) {
144 setFlagValue(ChannelFlags::Managed, other.managed);
145 setFlagValue(ChannelFlags::NSFW, other.nsfw);
146 if (
static_cast<int64_t
>(other.flags) != 0) {
149 if (other.memberCount != 0) {
152 if (other.topic !=
"") {
153 topic = std::move(other.topic);
155 if (other.name !=
"") {
156 name = std::move(other.name);
158 if (other.parentId != 0) {
161 if (other.position != 0) {
164 if (other.guildId != 0) {
167 if (other.ownerId != 0) {
179 returnData.
managed = getFlagValue(ChannelFlags::Managed);
180 returnData.permissionOverwrites = permissionOverwrites;
181 returnData.nsfw = getFlagValue(ChannelFlags::NSFW);
182 returnData.topic = topic.operator std::string();
183 returnData.name = name.operator std::string();
184 returnData.memberCount = memberCount;
185 returnData.parentId = parentId;
186 returnData.position = position;
187 returnData.guildId = guildId;
188 returnData.ownerId = ownerId;
189 returnData.flags = flags;
190 returnData.type = type;
195 ChannelCacheData::ChannelCacheData(
ChannelData&& other) {
196 *
this = std::move(other);
199 std::string ChannelData::getIconUrl() {
200 std::string stringNew{
"https://cdn.discordapp.com/" };
201 stringNew +=
"splashes/" +
id.operator std::string() +
"/" +
icon +
".png";
205 ModifyChannelData::ModifyChannelData(ChannelData newData) {
206 channelData.permissionOverwrites = newData.permissionOverwrites;
207 channelData.nsfw = newData.getFlagValue(ChannelFlags::NSFW);
208 channelData.rateLimitPerUser = newData.rateLimitPerUser;
218 void Channels::initialize(DiscordCoreInternal::HttpsClient* client, ConfigManager* configManagerNew) {
219 Channels::doWeCacheChannelsBool = configManagerNew->doWeCacheChannels();
220 Channels::httpsClient = client;
224 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Channel };
225 co_await NewThreadAwaitable<ChannelData>();
226 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
227 workload.relativePath =
"/channels/" + dataPackage.
channelId;
228 workload.callStack =
"Channels::getChannelAsync()";
230 if (cache.contains(data.id)) {
231 data = cache[data.id];
233 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), data);
234 if (doWeCacheChannelsBool) {
242 if (!Channels::cache.contains(data.id)) {
245 return cache[data.id];
250 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Patch_Channel };
251 co_await NewThreadAwaitable<ChannelData>();
252 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Patch;
253 workload.relativePath =
"/channels/" + dataPackage.
channelId;
254 parser.serializeJson(dataPackage, workload.content);
255 workload.callStack =
"Channels::modifyChannelAsync()";
256 if (dataPackage.
reason !=
"") {
257 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
260 if (cache.contains(data.id)) {
261 data = cache[data.id];
263 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), data);
264 if (doWeCacheChannelsBool) {
271 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Channel };
272 co_await NewThreadAwaitable<void>();
273 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
274 workload.relativePath =
"/channels/" + dataPackage.
channelId;
275 workload.callStack =
"Channels::deleteOrCloseAChannelAsync()";
276 if (dataPackage.
reason !=
"") {
277 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
279 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload));
284 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Put_Channel_Permission_Overwrites };
285 co_await NewThreadAwaitable<void>();
286 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Put;
287 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/permissions/" + dataPackage.
roleOrUserId;
288 parser.serializeJson(dataPackage, workload.content);
289 workload.callStack =
"Channels::editChannelPermissionOverwritesAsync()";
290 if (dataPackage.
reason !=
"") {
291 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
293 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload));
298 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Channel_Invites };
299 co_await NewThreadAwaitable<jsonifier::vector<InviteData>>();
300 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
301 workload.relativePath =
"/channels/" + dataPackage.channelId +
"/invites";
302 workload.callStack =
"Channels::getChannelInvitesAsync()";
303 jsonifier::vector<InviteData> returnData{};
304 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
305 co_return returnData;
309 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Channel_Invite };
310 co_await NewThreadAwaitable<InviteData>();
311 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
312 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/invites";
313 parser.serializeJson(dataPackage, workload.content);
314 workload.callStack =
"Channels::createChannelInviteAsync()";
315 if (dataPackage.
reason !=
"") {
316 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
319 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
320 co_return returnData;
324 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Channel_Permission_Overwrites };
325 co_await NewThreadAwaitable<void>();
326 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
327 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/permissions/" + dataPackage.
roleOrUserId;
328 workload.callStack =
"Channels::deleteChannelPermissionOverwritesAsync()";
329 if (dataPackage.
reason !=
"") {
330 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
332 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload));
337 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Follow_News_Channel };
338 co_await NewThreadAwaitable<ChannelData>();
339 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
340 workload.relativePath =
"/channels/" + dataPackage.channelId +
"/followers";
341 parser.serializeJson(dataPackage, workload.content);
342 workload.callStack =
"Channels::followNewsChannelAsync()";
344 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
345 co_return returnData;
349 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Trigger_Typing_Indicator };
350 co_await NewThreadAwaitable<void>();
351 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
352 workload.relativePath =
"/channels/" + dataPackage.channelId +
"/typing";
353 workload.callStack =
"Channels::triggerTypingIndicatorAsync()";
354 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload));
359 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Guild_Channels };
360 co_await NewThreadAwaitable<jsonifier::vector<ChannelData>>();
361 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
362 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/channels";
363 workload.callStack =
"Channels::getGuildChannelsAsync()";
364 jsonifier::vector<ChannelData> returnData{};
365 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
366 co_return returnData;
370 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Guild_Channel };
371 co_await NewThreadAwaitable<ChannelData>();
372 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
373 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/channels";
374 parser.serializeJson(dataPackage, workload.content);
375 workload.callStack =
"Channels::createGuildChannelAsync()";
376 if (dataPackage.
reason !=
"") {
377 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
380 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
381 co_return returnData;
385 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Patch_Guild_Channel_Positions };
386 co_await NewThreadAwaitable<void>();
387 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Patch;
388 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/channels";
389 parser.serializeJson(dataPackage, workload.content);
390 workload.callStack =
"Channels::modifyGuildChannelPositionsAsync()";
391 if (dataPackage.
reason !=
"") {
392 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
394 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload));
399 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Create_User_Dm };
400 co_await NewThreadAwaitable<ChannelData>();
401 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
402 workload.relativePath =
"/users/@me/channels";
403 workload.callStack =
"Channels::createDMChannelAsync()";
404 parser.serializeJson(dataPackage, workload.content);
406 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
407 co_return returnData;
411 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Voice_Regions };
412 co_await NewThreadAwaitable<jsonifier::vector<VoiceRegionData>>();
413 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
414 workload.relativePath =
"/voice/regions";
415 workload.callStack =
"Channels::getVoiceRegionsAsync()";
416 jsonifier::vector<VoiceRegionData> returnData{};
417 Channels::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
418 co_return returnData;
422 Channels::cache.erase(channelId);
425 bool Channels::doWeCacheChannels() {
426 return Channels::doWeCacheChannelsBool;
429 ObjectCache<ChannelCacheData> Channels::cache{};
430 DiscordCoreInternal::HttpsClient* Channels::httpsClient{};
431 bool Channels::doWeCacheChannelsBool{};
For collecting a Channel from Discord's servers.
Snowflake channelId
The id of the ChannelData to acquire.
For deleting or closing a Channel.
Snowflake channelId
The id of the ChannelData to close/delete.
std::string reason
The reason for deleting/closing the ChannelData.
For editing the PermissionTypes overwrites of a given Channel, for a given Role or UserData.
Snowflake roleOrUserId
The RoleData or UserData Snowflake to modify the permissions for.
std::string reason
Reason for editing the permission overwrites.
Snowflake channelId
The ChannelData id of the desired ChannelData to modify the permissions for.
For collecting the invites to a given Channel.
For creating an invite to a given Channel.
std::string reason
Reason for creating the invite.
Snowflake channelId
The id of the ChannelData to create the invite for.
For deleting the PermissionTypes overwrites of a given Channel for a given Role or UserData.
Snowflake channelId
The id of the ChannelData to modify permissions for.
Snowflake roleOrUserId
The RoleData or UserData id for whom to delete the PermissionTypes overwrites.
std::string reason
Reason for deleting these permission overwrites.
For following a news ChannelData.
For triggering the typing indicator in a given Channel.
For acquiring a list of Channels from a chosen Guild.
Snowflake guildId
The Guild from which to collect the Channels from.
For creating a new ChannelData within a chosen Guild.
std::string reason
Reason for creating the ChannelData.
Snowflake guildId
The Guild within which to create the ChannelData.
For modifying the ChannelData position responseData of a single ChannelData.
For modifying the current positions of one or more Channels in the Guild.
Snowflake guildId
Guild within which to re-order the ChannelData positions.
std::string reason
Reason for re-ordering the ChannelData positions.
For collecting a direct-messaging ChannelData.
For modifying a Channel's properties.
std::string reason
A reason for modifying the ChannelData.
Snowflake channelId
The id of the ChannelData to modify.
UpdateChannelData channelData
The responseData of the ChannelData to be updated.
static CoRoutine< void > deleteChannelPermissionOverwritesAsync(DeleteChannelPermissionOverwritesData dataPackage)
Delete the given std::string overwrites for a given User or RoleData.
static CoRoutine< jsonifier::vector< InviteData > > getChannelInvitesAsync(GetChannelInvitesData dataPackage)
Collects a vector of the invites to a given Channel.
static CoRoutine< ChannelData > followNewsChannelAsync(FollowNewsChannelData dataPackage)
Follows a given new ChannelData with another ChannelData.
static CoRoutine< ChannelData > createGuildChannelAsync(CreateGuildChannelData dataPackage)
Creates a new ChannelData within a chosen Guild.
static CoRoutine< void > modifyGuildChannelPositionsAsync(ModifyGuildChannelPositionsData dataPackage)
Re-orders the ChannelData positions, within a chosen Guild.
static CoRoutine< void > deleteOrCloseChannelAsync(DeleteOrCloseChannelData dataPackage)
Delete a Channel, or close a protected message.
static CoRoutine< jsonifier::vector< VoiceRegionData > > getVoiceRegionsAsync()
Collect a list of voice regions that are usable for the RTC-Region option of a given Channel.
static CoRoutine< jsonifier::vector< ChannelData > > getGuildChannelsAsync(GetGuildChannelsData dataPackage)
Collects a list of Channels from a chosen Guild.
static CoRoutine< ChannelData > getChannelAsync(GetChannelData dataPackage)
Collects a Channel from the Discord servers.
static ChannelCacheData getCachedChannel(GetChannelData dataPackage)
Collects a Channel from the library's cache.
static CoRoutine< ChannelData > modifyChannelAsync(ModifyChannelData dataPackage)
Modifies a Channel's properties.
static CoRoutine< void > triggerTypingIndicatorAsync(TriggerTypingIndicatorData dataPackage)
Triggers the typing indicator for the bot in the given Channel.
static CoRoutine< void > editChannelPermissionOverwritesAsync(EditChannelPermissionOverwritesData dataPackage)
Edit the given std::string overwrites for a given User or RoleData.
static CoRoutine< ChannelData > createDMChannelAsync(CreateDMChannelData dataPackage)
Collect a direct-MessageData Channel between the bot and the UserData.
static CoRoutine< InviteData > createChannelInviteAsync(CreateChannelInviteData dataPackage)
Creates an invite to a selected ChannelData.
A CoRoutine - representing a potentially asynchronous operation/function.
bool managed
For group DM channels: whether the channel is managed by an application via the gdm....
std::string icon
Icon hash of the group DM.
Data structure representing a single ChannelData.
uint32_t memberCount
Count of members active in the ChannelData.
ChannelType type
The type of the ChannelData.
jsonifier::string name
Name of the ChannelData.
Snowflake guildId
Snowflake of the ChannelData's Guild, if applicable.
ChannelFlags flags
Flags combined as a bitmask.
Snowflake parentId
Snowflake of the ChannelData's parent ChannelData/category.
jsonifier::string topic
ChannelData topic.
Snowflake ownerId
Snowflake of the ChannelData's owner.
uint32_t position
The position of the ChannelData, in the Guild's ChannelData list.
jsonifier::vector< OverWriteData > permissionOverwrites
Permission overwrites.
For updating/modifying a given Channel's properties.
uint64_t id
The Snowflake ID.