Skip to content

Commit

Permalink
feat: added bulk command deleting. (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Oct 11, 2023
1 parent c9562e5 commit a5ba94e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
22 changes: 20 additions & 2 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,6 @@ class DPP_EXPORT cluster {
*/
void guild_command_create(const slashcommand &s, snowflake guild_id, command_completion_event_t callback = utility::log_error());


/**
* @brief Create/overwrite guild slash commands.
* Any existing guild slash commands on this guild will be deleted and replaced with these.
Expand All @@ -1516,19 +1515,38 @@ class DPP_EXPORT cluster {
*/
void guild_bulk_command_create(const std::vector<slashcommand> &commands, snowflake guild_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Delete all existing guild slash commands.
*
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param guild_id Guild ID to delete the slash commands in.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::slashcommand_map object in confirmation_callback_t::value **which will be empty, meaning there are no commands**. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void guild_bulk_command_delete(snowflake guild_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Create/overwrite global slash commands.
* Any existing global slash commands will be deleted and replaced with these.
*
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param commands Vector of slash commands to create/update.
* overwriting existing commands that are registered globally for this application. Updates will be available in all guilds after 1 hour.
* overwriting existing commands that are registered globally for this application.
* Commands that do not already exist will count toward daily application command create limits.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::slashcommand_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void global_bulk_command_create(const std::vector<slashcommand> &commands, command_completion_event_t callback = utility::log_error());

/**
* @brief Delete all existing global slash commands.
*
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::slashcommand_map object in confirmation_callback_t::value **which will be empty, meaning there are no commands**. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void global_bulk_command_delete(command_completion_event_t callback = utility::log_error());

/**
* @brief Edit a global slash command (a bot can have a maximum of 100 of these)
*
Expand Down
23 changes: 22 additions & 1 deletion include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@
* @see dpp::cluster::global_bulk_command_create
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param commands Vector of slash commands to create/update.
* overwriting existing commands that are registered globally for this application. Updates will be available in all guilds after 1 hour.
* overwriting existing commands that are registered globally for this application.
* Commands that do not already exist will count toward daily application command create limits.
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_global_bulk_command_create(const std::vector<slashcommand> &commands);

/**
* @brief Delete all existing global slash commands.
*
* @see dpp::cluster::global_bulk_command_delete
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_global_bulk_command_delete();

/**
* @brief Create a global slash command (a bot can have a maximum of 100 of these).
*
Expand Down Expand Up @@ -108,6 +118,17 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_bulk_command_create(const std::vector<slashcommand> &commands, snowflake guild_id);

/**
* @brief Delete all existing guild slash commands.
*
* @see dpp::cluster::guild_bulk_command_delete
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param guild_id Guild ID to delete the slash commands in.
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_bulk_command_delete(snowflake guild_id);

/**
* @brief Get all slash command permissions of a guild
*
Expand Down
29 changes: 28 additions & 1 deletion include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @see dpp::cluster::global_bulk_command_create
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param commands Vector of slash commands to create/update.
* overwriting existing commands that are registered globally for this application. Updates will be available in all guilds after 1 hour.
* overwriting existing commands that are registered globally for this application.
* Commands that do not already exist will count toward daily application command create limits.
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
Expand All @@ -43,6 +43,19 @@
*/
slashcommand_map global_bulk_command_create_sync(const std::vector<slashcommand> &commands);

/**
* @brief Delete all existing global slash commands.
*
* @see dpp::cluster::global_bulk_command_delete
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
slashcommand_map global_bulk_command_delete_sync();

/**
* @brief Create a global slash command (a bot can have a maximum of 100 of these).
*
Expand Down Expand Up @@ -129,6 +142,20 @@ slashcommand_map global_commands_get_sync();
*/
slashcommand_map guild_bulk_command_create_sync(const std::vector<slashcommand> &commands, snowflake guild_id);

/**
* @brief Delete all existing guild slash commands.
*
* @see dpp::cluster::guild_bulk_command_delete
* @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
* @param guild_id Guild ID to delete the slash commands in.
* @return slashcommand_map returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
slashcommand_map guild_bulk_command_delete_sync(snowflake guild_id);

/**
* @brief Get all slash command permissions of a guild
*
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster/appcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void cluster::global_bulk_command_create(const std::vector<slashcommand> &comman
rest_request_list<slashcommand>(this, API_PATH "/applications", std::to_string(commands.size() > 0 && commands[0].application_id ? commands[0].application_id : me.id), "commands", m_put, j.dump(), callback);
}

void cluster::global_bulk_command_delete(command_completion_event_t callback) {
rest_request_list<slashcommand>(this, API_PATH "/applications", std::to_string(me.id), "commands", m_put, "{}", callback);
}

void cluster::global_command_create(const slashcommand &s, command_completion_event_t callback) {
rest_request<slashcommand>(this, API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "commands", m_post, s.build_json(false), callback);
}
Expand Down Expand Up @@ -59,6 +63,10 @@ void cluster::guild_bulk_command_create(const std::vector<slashcommand> &command
rest_request_list<slashcommand>(this, API_PATH "/applications", std::to_string(commands.size() > 0 && commands[0].application_id ? commands[0].application_id : me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_put, j.dump(), callback);
}

void cluster::guild_bulk_command_delete(snowflake guild_id, command_completion_event_t callback) {
rest_request_list<slashcommand>(this, API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_put, "{}", callback);
}

void cluster::guild_commands_get_permissions(snowflake guild_id, command_completion_event_t callback) {
rest_request_list<guild_command_permissions>(this, API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands/permissions", m_get, "", callback);
}
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ async<confirmation_callback_t> cluster::co_global_bulk_command_create(const std:
return async{ this, static_cast<void (cluster::*)(const std::vector<slashcommand> &, command_completion_event_t)>(&cluster::global_bulk_command_create), commands };
}

async<confirmation_callback_t> cluster::co_global_bulk_command_delete() {
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::global_bulk_command_delete) };
}

async<confirmation_callback_t> cluster::co_global_command_create(const slashcommand &s) {
return async{ this, static_cast<void (cluster::*)(const slashcommand &, command_completion_event_t)>(&cluster::global_command_create), s };
}
Expand All @@ -63,6 +67,10 @@ async<confirmation_callback_t> cluster::co_guild_bulk_command_create(const std::
return async{ this, static_cast<void (cluster::*)(const std::vector<slashcommand> &, snowflake, command_completion_event_t)>(&cluster::guild_bulk_command_create), commands, guild_id };
}

async<confirmation_callback_t> cluster::co_guild_bulk_command_delete(snowflake guild_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_bulk_command_delete), guild_id };
}

async<confirmation_callback_t> cluster::co_guild_commands_get_permissions(snowflake guild_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_commands_get_permissions), guild_id };
}
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ slashcommand_map cluster::global_bulk_command_create_sync(const std::vector<slas
return dpp::sync<slashcommand_map>(this, static_cast<void (cluster::*)(const std::vector<slashcommand> &, command_completion_event_t)>(&cluster::global_bulk_command_create), commands);
}

slashcommand_map cluster::global_bulk_command_delete_sync() {
return dpp::sync<slashcommand_map>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::global_bulk_command_delete));
}

slashcommand cluster::global_command_create_sync(const slashcommand &s) {
return dpp::sync<slashcommand>(this, static_cast<void (cluster::*)(const slashcommand &, command_completion_event_t)>(&cluster::global_command_create), s);
}
Expand All @@ -61,6 +65,10 @@ slashcommand_map cluster::guild_bulk_command_create_sync(const std::vector<slash
return dpp::sync<slashcommand_map>(this, static_cast<void (cluster::*)(const std::vector<slashcommand> &, snowflake, command_completion_event_t)>(&cluster::guild_bulk_command_create), commands, guild_id);
}

slashcommand_map cluster::guild_bulk_command_delete_sync(snowflake guild_id) {
return dpp::sync<slashcommand_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_bulk_command_delete), guild_id);
}

guild_command_permissions_map cluster::guild_commands_get_permissions_sync(snowflake guild_id) {
return dpp::sync<guild_command_permissions_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::guild_commands_get_permissions), guild_id);
}
Expand Down

0 comments on commit a5ba94e

Please sign in to comment.