diff options
author | Adam <Adam@anope.org> | 2011-07-14 02:31:12 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-07-14 02:31:12 -0400 |
commit | f858164deed48f2dcacd5ffc06a55398a54da7e8 (patch) | |
tree | 89c3cf36bd8e94942370135218d67d6d17ee222e /modules/core/cs_set.cpp | |
parent | 924f6849fee4598a1a3a7f1a98d96b79e5ffd3b4 (diff) |
Rewrote how commands are handled within Anope.
This allows naming commands and having spaces within command names.
Diffstat (limited to 'modules/core/cs_set.cpp')
-rw-r--r-- | modules/core/cs_set.cpp | 129 |
1 files changed, 28 insertions, 101 deletions
diff --git a/modules/core/cs_set.cpp b/modules/core/cs_set.cpp index e38d7f79f..c5ab3cbe5 100644 --- a/modules/core/cs_set.cpp +++ b/modules/core/cs_set.cpp @@ -12,117 +12,46 @@ /*************************************************************************/ #include "module.h" -#include "chanserv.h" class CommandCSSet : public Command { - typedef std::map<Anope::string, Command *, std::less<ci::string> > subcommand_map; - subcommand_map subcommands; - public: - CommandCSSet() : Command("SET", 2, 3) + CommandCSSet(Module *creator) : Command(creator, "chanserv/set", 2, 3) { this->SetDesc(_("Set channel options and information")); + this->SetSyntax(_("\037channel\037 \037option\037 \037parameters\037")); } - ~CommandCSSet() + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - this->subcommands.clear(); - } - - CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) - { - User *u = source.u; - - if (readonly) - { - source.Reply(_(CHAN_SET_DISABLED)); - return MOD_CONT; - } - if (!check_access(u, cs_findchan(params[0]), CA_SET)) - { - source.Reply(_(ACCESS_DENIED)); - return MOD_CONT; - } - - // XXX Remove after 1.9.4 release - if (params[1].equals_ci("MLOCK")) - { - source.Reply(_(CHAN_SET_MLOCK_DEPRECATED), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str()); - return MOD_CONT; - } - - Command *c = this->FindCommand(params[1]); - - if (c) - { - ChannelInfo *ci = source.ci; - Anope::string cmdparams = ci->name; - for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) - cmdparams += " " + *it; - mod_run_cmd(chanserv->Bot(), u, NULL, c, params[1], cmdparams); - } - else - { - source.Reply(_(NICK_SET_UNKNOWN_OPTION), Config->UseStrictPrivMsgString.c_str(), params[1].c_str()); - source.Reply(_(MORE_INFO), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str(), "SET"); - } - - return MOD_CONT; + this->OnSyntaxError(source, ""); + return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) { - if (subcommand.empty()) + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Allows the channel founder to set various channel options\n" + "and other information.\n" + " \n" + "Available options:")); + Anope::string this_name = source.command; + for (command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it) { - source.Reply(_("Syntax: \002SET \037channel\037 \037option\037 \037parameters\037\002\n" - " \n" - "Allows the channel founder to set various channel options\n" - "and other information.\n" - " \n" - "Available options:")); - for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it) - it->second->OnServHelp(source); - source.Reply(_("Type \002%s%s HELP SET \037option\037\002 for more information on a\n" - "particular option."), Config->UseStrictPrivMsgString.c_str(), Config->s_ChanServ.c_str()); - return true; + if (it->first.find_ci(this_name + " ") == 0) + { + service_reference<Command> command(it->second); + if (command) + { + source.command = it->first; + command->OnServHelp(source); + } + } } - else - { - Command *c = this->FindCommand(subcommand); - - if (c) - return c->OnHelp(source, subcommand); - } - - return false; - } - - void OnSyntaxError(CommandSource &source, const Anope::string &subcommand) - { - SyntaxError(source, "SET", _(CHAN_SET_SYNTAX)); - } - - bool AddSubcommand(Module *creator, Command *c) - { - c->module = creator; - c->service = this->service; - return this->subcommands.insert(std::make_pair(c->name, c)).second; - } - - bool DelSubcommand(Command *c) - { - return this->subcommands.erase(c->name); - } - - Command *FindCommand(const Anope::string &subcommand) - { - subcommand_map::const_iterator it = this->subcommands.find(subcommand); - - if (it != this->subcommands.end()) - return it->second; - - return NULL; + source.Reply(_("Type \002%s%s HELP SET \037option\037\002 for more information on a\n" + "particular option."), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str()); + return true; } }; @@ -131,14 +60,12 @@ class CSSet : public Module CommandCSSet commandcsset; public: - CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE) + CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandcsset(this) { this->SetAuthor("Anope"); - if (!chanserv) - throw ModuleException("ChanServ is not loaded!"); - - this->AddCommand(chanserv->Bot(), &commandcsset); + ModuleManager::RegisterService(&commandcsset); } }; |