DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
StageInstanceEntities.cpp
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/// StageInstanceEntities.cpp - Source file for the Stage Instance related stuff.
22/// Nov 29, 2021
23/// https://discordcoreapi.com
24/// \file StageInstanceEntities.cpp
25
28
29namespace DiscordCoreAPI {
30
31 StageInstance::StageInstance(simdjson::ondemand::value jsonObjectData) {
32 this->id = getId(jsonObjectData, "id");
33
34 this->guildId = getId(jsonObjectData, "guild_id");
35
36 this->channelId = getId(jsonObjectData, "channel_id");
37
38 this->topic = getString(jsonObjectData, "topic");
39
40 this->privacyLevel = static_cast<StageInstancePrivacyLevel>(getUint8(jsonObjectData, "privacy_level"));
41
42 this->discoverableDisabled = getBool(jsonObjectData, "discoverable_disabled");
43 }
44
45 void StageInstances::initialize(DiscordCoreInternal::HttpsClient* theClient) {
46 StageInstances::httpsClient = theClient;
47 }
48
50 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Stage_Instance };
51 co_await NewThreadAwaitable<StageInstance>();
52 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
53 workload.relativePath = "/stage-instances";
54 workload.callStack = "StageInstances::createStageInstanceAsync()";
55 JsonObject responseData{};
56 responseData["privacy_level"] = dataPackage.privacyLevel;
57 responseData["topic"] = dataPackage.topic;
58 responseData["channel_id"] = std::to_string(dataPackage.channelId);
59 workload.content = responseData;
60 if (dataPackage.reason != "") {
61 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
62 }
63 co_return StageInstances::httpsClient->submitWorkloadAndGetResult<StageInstance>(workload);
64 }
65
67 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Stage_Instance };
68 co_await NewThreadAwaitable<StageInstance>();
69 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
70 workload.relativePath = "/stage-instances/" + std::to_string(dataPackage.channelId);
71 workload.callStack = "StageInstances::getStageInstanceAsync()";
72 co_return StageInstances::httpsClient->submitWorkloadAndGetResult<StageInstance>(workload);
73 }
74
76 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Patch_Stage_Instance };
77 co_await NewThreadAwaitable<StageInstance>();
78 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Patch;
79 workload.relativePath = "/stage-instances/" + std::to_string(dataPackage.channelId);
80 JsonObject responseData{};
81 responseData["privacy_level"] = dataPackage.privacyLevel;
82 responseData["topic"] = dataPackage.topic;
83 workload.content = responseData;
84 workload.callStack = "StageInstances::modifyStageInstanceAsync()";
85 if (dataPackage.reason != "") {
86 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
87 }
88 co_return StageInstances::httpsClient->submitWorkloadAndGetResult<StageInstance>(workload);
89 }
90
92 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Stage_Instance };
93 co_await NewThreadAwaitable<void>();
94 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
95 workload.relativePath = "/stage-instances/" + std::to_string(dataPackage.channelId);
96 workload.callStack = "StageInstances::deleteStageInstanceAsync()";
97 if (dataPackage.reason != "") {
98 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
99 }
100 co_return StageInstances::httpsClient->submitWorkloadAndGetResult<void>(workload);
101 }
102 DiscordCoreInternal::HttpsClient* StageInstances::httpsClient{ nullptr };
103}
StageInstancePrivacyLevel
Stage instance privacy levels.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:62
Snowflake guildId
The Guild id for which the Channel exists in.
Bool discoverableDisabled
Is it discoverable?
String topic
The topic of the StageInstance.
StageInstancePrivacyLevel privacyLevel
Privacy level of the Channel.
Snowflake channelId
The Channel's id.
StageInstancePrivacyLevel privacyLevel
The privacy level of the Stage instance(default Guild_Only).
String reason
The reason for starting it.
String topic
The topic of the Stage instance(1 - 120 characters).
Snowflake channelId
The id of the Stage Channel.
For collecting a single StageInstance.
Snowflake channelId
The Channel id from which you would like to collect the StageInstance.
For modifying a single StageInstance.
String topic
The topic of the Stage instance(1 - 120 characters).
String reason
Reason for modifying the StageInstance.
StageInstancePrivacyLevel privacyLevel
The privacy level of the Stage instance.
Snowflake channelId
The Channel Id of the StageInstance.
For deleting a single StageInstance.
String reason
Reason for deleting the StageInstance.
Snowflake channelId
The Channel Id of the StageInstance.
static CoRoutine< StageInstance > getStageInstanceAsync(GetStageInstanceData dataPackage)
Collects a StageInstance.
static CoRoutine< StageInstance > modifyStageInstanceAsync(ModifyStageInstanceData dataPackage)
Modifies a StageInstance.
static CoRoutine< StageInstance > createStageInstanceAsync(CreateStageInstanceData dataPackage)
Creates a StageInstance.
static CoRoutine< void > deleteStageInstanceAsync(DeleteStageInstanceData dataPackage)
Deletes a StageInstance.