Skip to content

Commit

Permalink
feat: add support for application_integration_types
Browse files Browse the repository at this point in the history
  • Loading branch information
raxyte committed Aug 13, 2024
1 parent c6b99ea commit b21fe0a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/dpp/appcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,11 @@ class DPP_EXPORT slashcommand : public managed, public json_interface<slashcomma
*/
permission default_member_permissions;

/**
* @brief Installation contexts where the command is available, only for globally-scoped commands. Defaults to your app's configured contexts
*/
std::vector<application_integration_types> integration_types;

/**
* @brief Interaction context(s) where the command can be used, only for globally-scoped commands. By default, all interaction context types included for new commands.
*/
Expand Down
14 changes: 14 additions & 0 deletions include/dpp/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
************************************************************************************/

#pragma once
#include <dpp/integration.h>
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/managed.h>
Expand All @@ -30,6 +31,7 @@
#include <dpp/permissions.h>
#include <dpp/json_fwd.h>
#include <dpp/json_interface.h>
#include <map>

namespace dpp {

Expand Down Expand Up @@ -209,6 +211,13 @@ class DPP_EXPORT app_team {
snowflake owner_user_id;
};

/**
* * @brief Configuration object for an app installation
* */
struct integration_configuration {
std::optional<application_install_params> oauth2_install_params;
};

/**
* @brief The application class represents details of a bot application
*/
Expand Down Expand Up @@ -352,6 +361,11 @@ class DPP_EXPORT application : public managed, public json_interface<application
*/
application_install_params install_params;

/**
* @brief Default scopes and permissions for each supported installation context
*/
std::map<application_integration_types, integration_configuration> integration_types_config;

/**
* @brief The application's default custom authorization link, if enabled.
*/
Expand Down
14 changes: 14 additions & 0 deletions include/dpp/integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@

namespace dpp {

/**
* @brief Where an app can be installed, also called its supported installation contexts.
*/
enum application_integration_types {
/**
* @brief Installable to servers
*/
ait_guild_install = 0,
/**
* @brief Installable to users
*/
ait_user_install = 1,
};

/**
* @brief Integration types
*/
Expand Down
5 changes: 5 additions & 0 deletions src/dpp/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
************************************************************************************/
#include <dpp/application.h>
#include <dpp/discordevents.h>
#include <dpp/integration.h>
#include <dpp/snowflake.h>
#include <dpp/managed.h>
#include <dpp/json.h>
Expand Down Expand Up @@ -118,6 +119,10 @@ application& application::fill_from_json_impl(nlohmann::json* j) {
}
}

if (auto it = j->find("integration_types_config"); it != j->end()) {
it->get_to(this->integration_types_config);
}

set_string_not_null(j, "custom_install_url", custom_install_url);

// TODO: Investigate https://discord.com/developers/docs/resources/application#application-resource when v11 releases. See if the variables below are documented.
Expand Down
9 changes: 9 additions & 0 deletions src/dpp/slashcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ slashcommand& slashcommand::fill_from_json_impl(nlohmann::json* j) {

type = (slashcommand_contextmenu_type)int8_not_null(j, "type");
set_object_array_not_null<command_option>(j, "options", options); // command_option fills recursive

if (auto it = j->find("integration_types"); it != j->end()) {
it->get_to(this->integration_types);
}

if (auto it = j->find("contexts"); it != j->end()) {
std::copy(it->begin(), it->end(), std::back_inserter(contexts));
}
Expand Down Expand Up @@ -256,6 +261,10 @@ void to_json(json& j, const slashcommand& p) {
}
}

if (p.integration_types.size()) {
j["integration_types"] = p.integration_types;
}

// TODO: Maybe a std::optional is better to differentiate
if (p.contexts.size()) {
j["contexts"] = p.contexts;
Expand Down

0 comments on commit b21fe0a

Please sign in to comment.