DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
StickerEntities.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, 2023 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/// StickerEntities.cpp - Source file for the sticker related classes and structs.
22/// May 13, 2021
23/// https://discordcoreapi.com
24/// \file StickerEntities.cpp
25
28
29namespace Jsonifier {
30
31 template<> struct Core<DiscordCoreAPI::CreateGuildStickerData> {
33 static constexpr auto parseValue = object("description", &ValueType::description, "reason", &ValueType::reason, "guildId",
34 &ValueType::guildId, "file", &ValueType::file, "name", &ValueType::name, "tags", &ValueType::tags);
35 };
36
37 template<> struct Core<DiscordCoreAPI::ModifyGuildStickerData> {
39 static constexpr auto parseValue = object("description", &ValueType::description, "stickerId", &ValueType::stickerId, "reason",
40 &ValueType::reason, "guildId", &ValueType::guildId, "name", &ValueType::name, "tags", &ValueType::tags);
41 };
42
43}
44
45namespace DiscordCoreAPI {
46
47 void Stickers::initialize(DiscordCoreInternal::HttpsClient* client) {
48 Stickers::httpsClient = client;
49 }
50
52 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Sticker };
53 co_await NewThreadAwaitable<Sticker>();
54 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
55 workload.relativePath = "/stickers/" + dataPackage.stickerId;
56 workload.callStack = "Stickers::getStickerAsync()";
57 Sticker returnData{};
58 Stickers::httpsClient->submitWorkloadAndGetResult<Sticker>(workload, returnData);
59 co_return returnData;
60 }
61
63 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Nitro_Sticker_Packs };
64 co_await NewThreadAwaitable<std::vector<StickerPackData>>();
65 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
66 workload.relativePath = "/sticker-packs";
67 workload.callStack = "Stickers::getNitroStickerPacksAsync()";
68 StickerPackDataVector returnData{};
69 Stickers::httpsClient->submitWorkloadAndGetResult<StickerPackDataVector>(workload, returnData);
70 co_return returnData;
71 }
72
74 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Guild_Stickers };
75 co_await NewThreadAwaitable<std::vector<Sticker>>();
76 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
77 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers";
78 workload.callStack = "Stickers::getGuildStickersAsync()";
79 StickerVector returnData{};
80 Stickers::httpsClient->submitWorkloadAndGetResult<StickerVector>(workload, returnData);
81 co_return returnData;
82 }
83
85 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Guild_Sticker };
86 co_await NewThreadAwaitable<Sticker>();
87 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
88 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers";
89 Jsonifier::JsonifierCore parser{};
90 parser.serializeJson(dataPackage, workload.content);
91 workload.callStack = "Stickers::createGuildStickerAsync()";
92 if (dataPackage.reason != "") {
93 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
94 }
95 Sticker returnData{};
96 Stickers::httpsClient->submitWorkloadAndGetResult<Sticker>(workload, returnData);
97 co_return returnData;
98 }
99
101 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Patch_Guild_Sticker };
102 co_await NewThreadAwaitable<Sticker>();
103 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Patch;
104 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers/" + dataPackage.stickerId;
105 Jsonifier::JsonifierCore parser{};
106 parser.serializeJson(dataPackage, workload.content);
107 workload.callStack = "Stickers::modifyGuildStickerAsync()";
108 if (dataPackage.reason != "") {
109 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
110 }
111 Sticker returnData{};
112 Stickers::httpsClient->submitWorkloadAndGetResult<Sticker>(workload, returnData);
113 co_return returnData;
114 }
115
117 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Guild_Sticker };
118 co_await NewThreadAwaitable<void>();
119 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
120 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers/" + dataPackage.stickerId;
121 workload.callStack = "Stickers::deleteGuildStickerAsync()";
122 if (dataPackage.reason != "") {
123 workload.headersToInsert["X-Audit-Log-Reason"] = dataPackage.reason;
124 }
125 Stickers::httpsClient->submitWorkloadAndGetResult<void>(workload);
126 co_return;
127 }
128
129 DiscordCoreInternal::HttpsClient* Stickers::httpsClient{};
130};
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:52
For getting a Sticker object for the given sticker ID.
Snowflake stickerId
The chosen Sticker's Snowflake.
For collecting a list of Stickers from a chosen Guild.
Snowflake guildId
The chosen Guild from which you would like to collect the Stickers from.
For creating a single Sticker.
Snowflake guildId
The Guild within which to create the Sticker.
std::string reason
The reason for creating the Sticker.
For modifying a single Sticker.
Snowflake stickerId
The Sticker you wish to modify.
Snowflake guildId
The Guild within which to modify the Sticker.
std::string reason
The reason for modifying the Sticker.
For deleting a single Sticker.
Snowflake guildId
The Guild within which to delete the Sticker.
std::string reason
The reason for deleting the Sticker.
Snowflake stickerId
The Sticker you wish to delete.
static CoRoutine< Sticker > modifyGuildStickerAsync(ModifyGuildStickerData dataPackage)
Modifies a Sticker within a chosen Guild.
static CoRoutine< Sticker > getStickerAsync(GetStickerData dataPackage)
Gets a single Sticker item.
static CoRoutine< std::vector< StickerPackData > > getNitroStickerPacksAsync()
Gets a list of nitro-available Sticker packs.
static CoRoutine< std::vector< Sticker > > getGuildStickersAsync(GetGuildStickersData dataPackage)
Gets a list of Stickers from a Guild.
static CoRoutine< Sticker > createGuildStickerAsync(CreateGuildStickerData dataPackage)
Creates a new Sticker within a chosen Guild.
static CoRoutine< void > deleteGuildStickerAsync(DeleteGuildStickerData dataPackage)
Deletes a Sticker within a chosen Guild.