Commit ee4cf5dc authored by louiz’'s avatar louiz’

Add AdhocCommandHandlers::add_command to simplify the usage of this class

And make things a little bit clearer
parent 363a0bf0
...@@ -15,9 +15,9 @@ const std::map<const std::string, const AdhocCommand>& AdhocCommandsHandler::get ...@@ -15,9 +15,9 @@ const std::map<const std::string, const AdhocCommand>& AdhocCommandsHandler::get
return this->commands; return this->commands;
} }
std::map<const std::string, const AdhocCommand>& AdhocCommandsHandler::get_commands() void AdhocCommandsHandler::add_command(std::string name, AdhocCommand command)
{ {
return this->commands; this->commands.emplace(std::make_pair(std::move(name), std::move(command)));
} }
XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node) XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node)
......
...@@ -31,9 +31,9 @@ public: ...@@ -31,9 +31,9 @@ public:
*/ */
const std::map<const std::string, const AdhocCommand>& get_commands() const; const std::map<const std::string, const AdhocCommand>& get_commands() const;
/** /**
* This one can be used to add new commands. * Add a command into the list, associated with the given name
*/ */
std::map<const std::string, const AdhocCommand>& get_commands(); void add_command(std::string name, AdhocCommand command);
/** /**
* Find the requested command, create a new session or use an existing * Find the requested command, create a new session or use an existing
* one, and process the request (provide a new form, an error, or a * one, and process the request (provide a new form, an error, or a
......
...@@ -56,35 +56,24 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::st ...@@ -56,35 +56,24 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::st
this->stanza_handlers.emplace("iq", this->stanza_handlers.emplace("iq",
std::bind(&BiboumiComponent::handle_iq, this,std::placeholders::_1)); std::bind(&BiboumiComponent::handle_iq, this,std::placeholders::_1));
this->adhoc_commands_handler.get_commands() = { this->adhoc_commands_handler.add_command("ping", {{&PingStep1}, "Do a ping", false});
{"ping", AdhocCommand({&PingStep1}, "Do a ping", false)}, this->adhoc_commands_handler.add_command("hello", {{&HelloStep1, &HelloStep2}, "Receive a custom greeting", false});
{"hello", AdhocCommand({&HelloStep1, &HelloStep2}, "Receive a custom greeting", false)}, this->adhoc_commands_handler.add_command("disconnect-user", {{&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect selected users from the gateway", true});
{"disconnect-user", AdhocCommand({&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect selected users from the gateway", true)}, this->adhoc_commands_handler.add_command("hello", {{&HelloStep1, &HelloStep2}, "Receive a custom greeting", false});
{"disconnect-from-irc-servers", AdhocCommand({&DisconnectUserFromServerStep1, &DisconnectUserFromServerStep2, &DisconnectUserFromServerStep3}, "Disconnect from the selected IRC servers", false)}, this->adhoc_commands_handler.add_command("reload", {{&Reload}, "Reload biboumi’s configuration", true});
{"reload", AdhocCommand({&Reload}, "Reload biboumi’s configuration", true)}
};
#ifdef USE_DATABASE #ifdef USE_DATABASE
AdhocCommand configure_server_command({&ConfigureIrcServerStep1, &ConfigureIrcServerStep2}, "Configure a few settings for that IRC server", false); AdhocCommand configure_server_command({&ConfigureIrcServerStep1, &ConfigureIrcServerStep2}, "Configure a few settings for that IRC server", false);
AdhocCommand configure_global_command({&ConfigureGlobalStep1, &ConfigureGlobalStep2}, "Configure a few settings", false); AdhocCommand configure_global_command({&ConfigureGlobalStep1, &ConfigureGlobalStep2}, "Configure a few settings", false);
if (!Config::get("fixed_irc_server", "").empty()) if (!Config::get("fixed_irc_server", "").empty())
this->adhoc_commands_handler.get_commands().emplace(std::make_pair("configure", this->adhoc_commands_handler.add_command("configure", configure_server_command);
configure_server_command));
else else
this->adhoc_commands_handler.get_commands().emplace(std::make_pair("configure", this->adhoc_commands_handler.add_command("configure", configure_global_command);
configure_global_command));
#endif
this->irc_server_adhoc_commands_handler.get_commands() = { this->irc_server_adhoc_commands_handler.add_command("configure", configure_server_command);
#ifdef USE_DATABASE this->irc_channel_adhoc_commands_handler.add_command("configure", {{&ConfigureIrcChannelStep1, &ConfigureIrcChannelStep2}, "Configure a few settings for that IRC channel", false});
{"configure", configure_server_command},
#endif
};
this->irc_channel_adhoc_commands_handler.get_commands() = {
#ifdef USE_DATABASE
{"configure", AdhocCommand({&ConfigureIrcChannelStep1, &ConfigureIrcChannelStep2}, "Configure a few settings for that IRC channel", false)},
#endif #endif
};
} }
void BiboumiComponent::shutdown() void BiboumiComponent::shutdown()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment