DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
ApplicationCommandEntities.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/// ApplicationCommandEntities.cpp - Source file for the application_command_data classes and structs.
27/// Aug 25, 2021
28/// https://discordcoreapi.com
29/// \file ApplicationCommandEntities.cpp
30
36
37namespace jsonifier {
38
39 template<> struct core<discord_core_api::create_global_application_command_data> {
40 using value_type = discord_core_api::create_global_application_command_data;
41 static constexpr auto parseValue = createValue("id", &value_type::id, "application_id", &value_type::applicationId, "name", &value_type::name, "description",
42 &value_type::description, "type", &value_type::type, "default_permission", &value_type::defaultMemberPermissions, "options", &value_type::options, "version",
43 &value_type::version, "guild_id", &value_type::guildId, "dm_permission", &value_type::dmPermission, "name_localizations", &value_type::nameLocalizations,
44 "description_localizations", &value_type::descriptionLocalizations);
45 };
46
47 template<> struct core<discord_core_api::create_guild_application_command_data> {
48 using value_type = discord_core_api::create_guild_application_command_data;
49 static constexpr auto parseValue = createValue("id", &value_type::id, "application_id", &value_type::applicationId, "name", &value_type::name, "description",
50 &value_type::description, "type", &value_type::type, "default_permission", &value_type::defaultMemberPermissions, "options", &value_type::options, "version",
51 &value_type::version, "guild_id", &value_type::guildId, "dm_permission", &value_type::dmPermission, "name_localizations", &value_type::nameLocalizations,
52 "description_localizations", &value_type::descriptionLocalizations);
53 };
54
55 template<> struct core<discord_core_api::bulk_overwrite_global_application_commands_data> {
56 using value_type = discord_core_api::bulk_overwrite_global_application_commands_data;
57 static constexpr auto parseValue = createValue("commands", &value_type::responseData, "application_id", &value_type::applicationId);
58 };
59
60 template<> struct core<discord_core_api::edit_global_application_command_data> {
61 using value_type = discord_core_api::edit_global_application_command_data;
62 static constexpr auto parseValue = createValue("name", &value_type::name, "description", &value_type::description, "options", &value_type::options, "default_permission",
63 &value_type::defaultMemberPermissions, "name_localization", &value_type::nameLocalizations, "description_localization", &value_type::descriptionLocalizations,
64 "application_id", &value_type::applicationId, "dm_permission", &value_type::dmPermission);
65 };
66
67 template<> struct core<discord_core_api::edit_guild_application_command_data> {
68 using value_type = discord_core_api::edit_guild_application_command_data;
69 static constexpr auto parseValue = createValue("description_localizations", &value_type::descriptionLocalizations, "name_localizations", &value_type::nameLocalizations,
70 "options", &value_type::options, "default_permission", &value_type::defaultMemberPermissions, "description", &value_type::description, "application_id",
71 &value_type::applicationId, "guild_id", &value_type::guildId, "name", &value_type::name);
72 };
73
74 template<> struct core<discord_core_api::bulk_overwrite_guild_application_commands_data> {
75 using value_type = discord_core_api::bulk_overwrite_guild_application_commands_data;
76 static constexpr auto parseValue = createValue("commands", &value_type::responseData, "application_id", &value_type::applicationId, "guild_id", &value_type::guildId);
77 };
78
79 template<> struct core<discord_core_api::edit_guild_application_command_permissions_data> {
80 using value_type = discord_core_api::edit_guild_application_command_permissions_data;
81 static constexpr auto parseValue = createValue("permissions", &value_type::permissions, "command", &value_type::commandName, "application_id", &value_type::applicationId,
82 "id", &value_type::commandId, "guild_id", &value_type::guildId);
83 };
84
85 template<> struct core<discord_core_api::batch_edit_guild_application_command_permissions_data> {
86 using value_type = discord_core_api::batch_edit_guild_application_command_permissions_data;
87 static constexpr auto parseValue = createValue("permissions", &value_type::permissions, "application_id", &value_type::applicationId, "guild_id", &value_type::guildId);
88 };
89}
90
91namespace discord_core_api {
92
93 void application_commands::initialize(discord_core_internal::https_client* client) {
94 application_commands::httpsClient = client;
95 }
96
98 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Global_Application_Commands };
100 workload.workloadClass = discord_core_internal::https_workload_class::Get;
101 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands";
102 if (dataPackage.withLocalizations) {
103 workload.relativePath += "?with_localizations=true";
104 }
105 workload.callStack = "application_commands::getGlobalApplicationCommandsAsync()";
106 jsonifier::vector<application_command_data> returnData{};
107 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
108 co_return returnData;
109 }
110
112 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Global_Application_Command };
114 workload.workloadClass = discord_core_internal::https_workload_class::Post;
115 dataPackage.generateExcludedKeys();
116 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands";
117 parser.serializeJson(dataPackage, workload.content);
118 workload.callStack = "application_commands::createGlobalApplicationCommandAsync()";
119 application_command_data returnData{};
120 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
121 co_return returnData;
122 }
123
125 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Global_Application_Command };
127 workload.workloadClass = discord_core_internal::https_workload_class::Get;
128 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands/" + dataPackage.commandId;
129 workload.callStack = "application_commands::getGlobalApplicationCommandAsync()";
130 application_command_data returnData{};
131 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
132 co_return returnData;
133 }
134
136 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Global_Application_Command };
138 jsonifier::vector<application_command_data> appCommands = getGlobalApplicationCommandsAsync({ .applicationId = dataPackage.applicationId }).get();
139 bool isItFound{};
140 snowflake appCommandId{};
141 for (auto& value: appCommands) {
142 if (value.name == dataPackage.name) {
143 appCommandId = value.id;
144 isItFound = true;
145 }
146 }
147 if (!isItFound) {
148 co_return application_command_data();
149 }
150 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
151 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands/" + appCommandId.operator jsonifier::string();
152 parser.serializeJson(dataPackage, workload.content);
153 workload.callStack = "application_commands::editGlobalApplicationCommandAsync()";
154 application_command_data returnData{};
155 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
156 co_return returnData;
157 }
158
160 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Global_Application_Command };
161 co_await newThreadAwaitable<void>();
162 jsonifier::vector<application_command_data> appCommands = getGlobalApplicationCommandsAsync({ .applicationId = dataPackage.applicationId }).get();
163 snowflake commandId{};
164 bool isItFound = false;
165 for (auto& value: appCommands) {
166 if (value.name == dataPackage.name) {
167 commandId = value.id;
168 isItFound = true;
169 }
170 }
171 if (!isItFound) {
172 co_return;
173 }
174 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
175 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands/" + commandId.operator jsonifier::string();
176 workload.callStack = "application_commands::deleteGlobalApplicationCommandAsync()";
177 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload));
178 co_return;
179 }
180
183 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Bulk_Put_Global_Application_Commands };
185 workload.workloadClass = discord_core_internal::https_workload_class::Put;
186 workload.relativePath = "/applications/" + dataPackage.applicationId + "/commands";
187 parser.serializeJson(dataPackage, workload.content);
188 workload.callStack = "application_commands::bulkOverwriteGlobalApplicationCommandsAsync()";
189 jsonifier::vector<application_command_data> returnData{};
190 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
191 co_return returnData;
192 }
193
195 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Application_Commands };
197 workload.workloadClass = discord_core_internal::https_workload_class::Get;
198 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands";
199 if (dataPackage.withLocalizations) {
200 workload.relativePath += "?with_localizations=true";
201 }
202 workload.callStack = "application_commands::getGuildApplicationCommandsAsync()";
203 jsonifier::vector<application_command_data> returnData{};
204 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
205 co_return returnData;
206 }
207
209 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Guild_Application_Command };
211 dataPackage.applicationId = dataPackage.applicationId;
212 workload.workloadClass = discord_core_internal::https_workload_class::Post;
213 dataPackage.generateExcludedKeys();
214 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands";
215 parser.serializeJson(dataPackage, workload.content);
216 workload.callStack = "application_commands::createGuildApplicationCommandAsync()";
217 application_command_data returnData{};
218 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
219 co_return returnData;
220 }
221
223 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Application_Command };
225 workload.workloadClass = discord_core_internal::https_workload_class::Get;
226 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/" + dataPackage.commandId;
227 workload.callStack = "application_commands::getGuildApplicationCommandAsync()";
228 application_command_data returnData{};
229 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
230 co_return returnData;
231 }
232
234 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Guild_Application_Command };
236 jsonifier::vector<application_command_data> appCommands = getGuildApplicationCommandsAsync({ .guildId = dataPackage.guildId }).get();
237 bool isItFound = false;
238 snowflake appCommandId{};
239 for (auto& value: appCommands) {
240 if (value.name == dataPackage.name) {
241 appCommandId = value.id;
242 isItFound = true;
243 }
244 }
245 if (!isItFound) {
246 co_return application_command_data();
247 }
248 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
249 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/" + appCommandId;
250 parser.serializeJson(dataPackage, workload.content);
251 workload.callStack = "application_commands::editGuildApplicationCommandAsync()";
252 application_command_data returnData{};
253 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
254 co_return returnData;
255 }
256
258 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Guild_Application_Command };
259 co_await newThreadAwaitable<void>();
260 jsonifier::vector<application_command_data> appCommands = getGuildApplicationCommandsAsync({ .guildId = dataPackage.guildId }).get();
261 snowflake commandId;
262 bool isItFound = false;
263 for (auto& value: appCommands) {
264 if (value.name == dataPackage.name) {
265 commandId = value.id;
266 isItFound = true;
267 }
268 }
269 if (!isItFound) {
270 co_return;
271 }
272 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
273 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/" + commandId;
274 workload.callStack = "application_commands::deleteGuildApplicationCommandAsync()";
275 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload));
276 co_return;
277 }
278
281 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Bulk_Put_Guild_Application_Commands };
283 parser.serializeJson(dataPackage, workload.content);
284 workload.workloadClass = discord_core_internal::https_workload_class::Put;
285 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands";
286 workload.callStack = "application_commands::bulkOverwriteGuildApplicationCommandsAsync()";
287 jsonifier::vector<application_command_data> returnData{};
288 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
289 co_return returnData;
290 }
291
294 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Application_Commands_Permissions };
296 workload.workloadClass = discord_core_internal::https_workload_class::Get;
297 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/permissions";
298 workload.callStack = "application_commands::getGuildApplicationCommandPermissionsAsync()";
299 jsonifier::vector<guild_application_command_permissions_data> returnData{};
300 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
301 co_return returnData;
302 }
303
305 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Application_Command_Permissions };
307 jsonifier::vector<application_command_data> appCommands = getGuildApplicationCommandsAsync({ .guildId = dataPackage.guildId }).get();
308 snowflake commandId;
309 bool isItFound = false;
310 for (auto& value: appCommands) {
311 if (value.name == dataPackage.commandName) {
312 commandId = value.id;
313 isItFound = true;
314 }
315 }
316 if (!isItFound) {
317 co_return guild_application_command_permissions_data();
318 }
319 workload.workloadClass = discord_core_internal::https_workload_class::Get;
320 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/" + commandId + "/permissions";
321 workload.callStack = "application_commands::getApplicationCommandPermissionsAsync()";
322 guild_application_command_permissions_data returnData{};
323 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
324 co_return returnData;
325 }
326
329 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Put_Guild_Application_Command_Permissions };
331 jsonifier::vector<application_command_data> appCommands = getGuildApplicationCommandsAsync({ .guildId = dataPackage.guildId }).get();
332 snowflake commandId;
333 bool isItFound = false;
334 for (auto& value: appCommands) {
335 if (value.name == dataPackage.commandName) {
336 commandId = value.id;
337 isItFound = true;
338 }
339 }
340 if (!isItFound) {
341 co_return guild_application_command_permissions_data();
342 }
343 workload.workloadClass = discord_core_internal::https_workload_class::Put;
344 workload.relativePath = "/applications/" + dataPackage.applicationId + "/guilds/" + dataPackage.guildId + "/commands/" + commandId + "/permissions";
345 parser.serializeJson(dataPackage, workload.content);
346 workload.callStack = "application_commands::editGuildApplicationCommandPermissionsAsync()";
347 guild_application_command_permissions_data returnData{};
348 application_commands::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
349 co_return returnData;
350 }
351
352 discord_core_internal::https_client* application_commands::httpsClient{};
353}
snowflake applicationId
The current application id.
snowflake guildId
(where applicable) a guild id for which guild to assign this application_command_data to.
static co_routine< jsonifier::vector< application_command_data > > getGlobalApplicationCommandsAsync(get_global_application_commands_data dataPackage)
Get all of the global application_commands for this bot.
static co_routine< void > deleteGlobalApplicationCommandAsync(delete_global_application_command_data dataPackage)
Delete a global application_command_data for this bot.
static co_routine< jsonifier::vector< application_command_data > > bulkOverwriteGlobalApplicationCommandsAsync(bulk_overwrite_global_application_commands_data dataPackage)
Bulk overwrites a collection of global application_commands.
static co_routine< application_command_data > getGlobalApplicationCommandAsync(get_global_application_command_data dataPackage)
Get a single global application_command_data for this bot.
static co_routine< guild_application_command_permissions_data > editGuildApplicationCommandPermissionsAsync(const edit_guild_application_command_permissions_data dataPackage)
Edit guild application_command_data permissions for a server on this bot.
static co_routine< jsonifier::vector< application_command_data > > getGuildApplicationCommandsAsync(get_guild_application_commands_data dataPackage)
Get all of the guild application_commands for a single guild for this bot.
static co_routine< application_command_data > createGlobalApplicationCommandAsync(create_global_application_command_data dataPackage)
Create a global application_command_data for this bot.
static co_routine< jsonifier::vector< guild_application_command_permissions_data > > getGuildApplicationCommandPermissionsAsync(const get_guild_application_command_permissions_data dataPackage)
Gets guild application_command_data permissions for a single server on this bot.
static co_routine< application_command_data > editGlobalApplicationCommandAsync(edit_global_application_command_data dataPackage)
Edit a global application_command_data for this bot.
static co_routine< application_command_data > createGuildApplicationCommandAsync(create_guild_application_command_data dataPackage)
Create a guild application_command_data for a single server for this bot.
static co_routine< jsonifier::vector< application_command_data > > bulkOverwriteGuildApplicationCommandsAsync(bulk_overwrite_guild_application_commands_data dataPackage)
Bulkoverwrites some guild application_commands for this bot.
static co_routine< guild_application_command_permissions_data > getApplicationCommandPermissionsAsync(get_application_command_permissions_data dataPackage)
Get application_command_data permissions for a single command on this bot.
static co_routine< application_command_data > editGuildApplicationCommandAsync(edit_guild_application_command_data dataPackage)
Edit a single guild application_command_data for a single server for this bot.
static co_routine< void > deleteGuildApplicationCommandAsync(delete_guild_application_command_data dataPackage)
Delete a single guild application_command_data for a single server for this bot.
static co_routine< application_command_data > getGuildApplicationCommandAsync(get_guild_application_command_data dataPackage)
Get a single guild application_command_data for a single server for this bot.
A co_routine - representing a potentially asynchronous operation/function.
uint64_t id
The snowflake id.
Definition Base.hpp:832
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 bulk-overwriting a collection of global application_commands.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For bulk-overwriting a collection of guild application_commands.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
snowflake guildId
The id of the guild which you would like to overwrite the commands of.
For creating a single global application_command_data.
For creating a single guild application_command_data.
For deleting a single global application_command_data.
jsonifier::string name
The name of the command to delete.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For deleting a single guild application_command_data.
jsonifier::string name
A name of the command which you would like to delete.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
snowflake guildId
The id of the guild which you would like to delete the command from.
For editing a single global application_command_data.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For editing a single guild application_command_data.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
snowflake guildId
The id of the guild which you would like to add the new command to.
For editing the permissions of a single guild application_command_data.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
jsonifier::string commandName
The command name which you would like to edit the permissions of.
snowflake guildId
The guild id of the guild for which you would like to edit the command permissions.
For acquiring the permissions of a single guild application_command_data.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
snowflake guildId
The id of the guild from which you would like to acquire the command permissions.
jsonifier::string commandName
The name of the command which you would like to collect the permissions of.
For collecting a single global application_command_data.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
jsonifier::string commandId
The id of the command which you would like to collect.
For getting all of the global application commands.
bool withLocalizations
Do we collect the name-and-description localizations?
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For acquiring a single guild application_command_data.
snowflake guildId
The id of the guild from which you would like to acquire the application_command_data from.
snowflake commandId
The command id which you would like to acquire.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For acquiring the permissions of a collection of guild application_commands.
snowflake guildId
The id of the guild from which you would like to acquire the command permissions.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
For acquiring all of the guild application_commands of a single guild.
snowflake applicationId
The current application's snowflake (the bot's user_data snowflake).
bool withLocalizations
Do we collect the name-and-description localizations?
snowflake guildId
The id of the guild for which you would like to acquire the application_commands from.