1
0
mirror of https://github.com/anope/anope.git synced 2026-07-02 03:46:39 +02:00

Rewrote how commands are handled within Anope.

This allows naming commands and having spaces within command names.
This commit is contained in:
Adam
2011-07-14 02:31:12 -04:00
parent 924f6849fe
commit f858164dee
227 changed files with 8808 additions and 12352 deletions
+28 -101
View File
@@ -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> &params)
{
this->subcommands.clear();
}
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params)
{
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);
}
};