Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added bulk command deleting. #938

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion 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,6 +1515,17 @@ 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.
* Updates will be available in all guilds after 1 hour.
*
* @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.
Expand All @@ -1529,6 +1539,16 @@ class DPP_EXPORT cluster {
*/
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.
* Updates will be available in all guilds after 1 hour.
*
* @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
29 changes: 29 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@
*/
slashcommand_map global_bulk_command_create_sync(const std::vector<slashcommand> &commands);

/**
* @brief Delete all existing global slash commands.
* Updates will be available in all guilds after 1 hour.
*
* @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 +143,21 @@ 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.
* Updates will be available in all guilds after 1 hour.
*
* @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_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