diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index 0e064ce27d..1d09fb4e91 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -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 + std::enable_if_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(handler)); + return inserted; + } /** * @brief Get the number of currently active HTTP(S) requests active in the cluster. @@ -608,12 +613,12 @@ class DPP_EXPORT cluster { * the command with the same name already exists. */ template - std::enable_if_t, dpp::task>, bool> - register_command(const std::string& name, F&& handler){ + requires (utility::callable_returns, 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(handler)); + auto [_, inserted] = named_commands.try_emplace(name, std::in_place_type, std::forward(handler)); return inserted; - }; + } #endif /** diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index 272e642d81..1888dccdca 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -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;