Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,12 @@ class DPP_EXPORT cluster {
* @return bool Returns `true` if the command was registered successfully, or `false` if
* the command with the same name already exists
*/
bool register_command(const std::string& name, const slashcommand_handler_t handler);
template <typename F>
std::enable_if_t<utility::callable_returns_v<F, void, const slashcommand_t&>, bool> register_command(const std::string& name, F&& handler) {
std::unique_lock lk(named_commands_mutex);
auto [_, inserted] = named_commands.try_emplace(name, std::forward<F>(handler));
return inserted;
}

/**
* @brief Get the number of currently active HTTP(S) requests active in the cluster.
Expand All @@ -608,12 +613,12 @@ class DPP_EXPORT cluster {
* the command with the same name already exists.
*/
template <typename F>
std::enable_if_t<std::is_same_v<std::invoke_result_t<F, const slashcommand_handler_t&>, dpp::task<void>>, bool>
register_command(const std::string& name, F&& handler){
requires (utility::callable_returns<F, dpp::task<void>, const slashcommand_t&>)
bool register_command(const std::string& name, F&& handler) {
std::unique_lock lk(named_commands_mutex);
auto [_, inserted] = named_commands.try_emplace(name, std::forward<F>(handler));
auto [_, inserted] = named_commands.try_emplace(name, std::in_place_type<co_slashcommand_handler_t>, std::forward<F>(handler));
return inserted;
};
}
#endif

/**
Expand Down
6 changes: 0 additions & 6 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,6 @@ cluster& cluster::set_request_timeout(uint16_t timeout) {
return *this;
}

bool cluster::register_command(const std::string &name, const slashcommand_handler_t handler) {
std::unique_lock lk(named_commands_mutex);
auto [_, inserted] = named_commands.try_emplace(name, handler);
return inserted;
}

bool cluster::unregister_command(const std::string &name) {
std::unique_lock lk(named_commands_mutex);
return named_commands.erase(name) == 1;
Expand Down
Loading