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 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/// StickerEntities.cpp - Source file for the sticker related classes and structs.
27/// May 13, 2021
28/// https://discordcoreapi.com
29/// \file StickerEntities.cpp
30
34
35namespace jsonifier {
36
37 template<> struct core<discord_core_api::create_guild_sticker_data> {
38 using value_type = discord_core_api::create_guild_sticker_data;
39 static constexpr auto parseValue = createValue("description", &value_type::description, "guildId", &value_type::guildId, "file",
40 &value_type::file, "name", &value_type::name, "tags", &value_type::tags);
41 };
42
43 template<> struct core<discord_core_api::modify_guild_sticker_data> {
44 using value_type = discord_core_api::modify_guild_sticker_data;
45 static constexpr auto parseValue = createValue("description", &value_type::description, "stickerId", &value_type::stickerId, "guildId",
46 &value_type::guildId, "name", &value_type::name, "tags", &value_type::tags);
47 };
48
49}
50
51namespace discord_core_api {
52
53 void stickers::initialize(discord_core_internal::https_client* client) {
54 stickers::httpsClient = client;
55 }
56
58 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Sticker };
60 workload.workloadClass = discord_core_internal::https_workload_class::Get;
61 workload.relativePath = "/stickers/" + dataPackage.stickerId;
62 workload.callStack = "stickers::getStickerAsync()";
63 sticker_data returnData{};
64 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
65 co_return returnData;
66 }
67
69 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Nitro_Sticker_Packs };
71 workload.workloadClass = discord_core_internal::https_workload_class::Get;
72 workload.relativePath = "/sticker-packs";
73 workload.callStack = "stickers::getNitroStickerPacksAsync()";
74 jsonifier::vector<sticker_pack_data> returnData{};
75 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
76 co_return returnData;
77 }
78
80 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Stickers };
82 workload.workloadClass = discord_core_internal::https_workload_class::Get;
83 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers";
84 workload.callStack = "stickers::getGuildStickersAsync()";
85 jsonifier::vector<sticker_data> returnData{};
86 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
87 co_return returnData;
88 }
89
91 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Guild_Sticker };
93 workload.workloadClass = discord_core_internal::https_workload_class::Post;
94 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers";
95 parser.serializeJson(dataPackage, workload.content);
96 workload.callStack = "stickers::createGuildStickerAsync()";
97 if (dataPackage.reason != "") {
98 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
99 }
100 sticker_data returnData{};
101 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
102 co_return returnData;
103 }
104
106 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Guild_Sticker };
108 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
109 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers/" + dataPackage.stickerId;
110 parser.serializeJson(dataPackage, workload.content);
111 workload.callStack = "stickers::modifyGuildStickerAsync()";
112 if (dataPackage.reason != "") {
113 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
114 }
115 sticker_data returnData{};
116 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
117 co_return returnData;
118 }
119
121 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Guild_Sticker };
122 co_await newThreadAwaitable<void>();
123 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
124 workload.relativePath = "/guilds/" + dataPackage.guildId + "/stickers/" + dataPackage.stickerId;
125 workload.callStack = "stickers::deleteGuildStickerAsync()";
126 if (dataPackage.reason != "") {
127 workload.headersToInsert["x-audit-log-reason"] = dataPackage.reason;
128 }
129 stickers::httpsClient->submitWorkloadAndGetResult(std::move(workload));
130 co_return;
131 }
132
133 discord_core_internal::https_client* stickers::httpsClient{};
134};
A co_routine - representing a potentially asynchronous operation/function.
static co_routine< jsonifier::vector< sticker_data > > getGuildStickersAsync(get_guild_stickers_data dataPackage)
Gets a list of stickers from a guild.
static co_routine< void > deleteGuildStickerAsync(delete_guild_sticker_data dataPackage)
Deletes a sticker_data within a chosen guild.
static co_routine< jsonifier::vector< sticker_pack_data > > getNitroStickerPacksAsync()
Gets a list of nitro-available sticker_data packs.
static co_routine< sticker_data > getStickerAsync(get_sticker_data dataPackage)
Gets a single sticker_data item.
static co_routine< sticker_data > createGuildStickerAsync(create_guild_sticker_data dataPackage)
Creates a new sticker_data within a chosen guild.
static co_routine< sticker_data > modifyGuildStickerAsync(modify_guild_sticker_data dataPackage)
Modifies a sticker_data within a chosen guild.
DCA_INLINE auto newThreadAwaitable()
An awaitable that can be used to launch the co_routine onto a new thread - as well as return the hand...
The main namespace for the forward-facing interfaces.
For creating a single sticker_data.
jsonifier::string reason
The reason for creating the sticker_data.
snowflake guildId
The guild within which to create the sticker_data.
For deleting a single sticker_data.
snowflake stickerId
The sticker_data you wish to delete.
snowflake guildId
The guild within which to delete the sticker_data.
jsonifier::string reason
The reason for deleting the sticker_data.
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 getting a sticker_data object for the given sticker id.
snowflake stickerId
The chosen sticker_data's snowflake.
For modifying a single sticker_data.
snowflake stickerId
The sticker_data you wish to modify.
jsonifier::string reason
The reason for modifying the sticker_data.
snowflake guildId
The guild within which to modify the sticker_data.