diff options
author | Adam <Adam@anope.org> | 2010-11-14 15:12:32 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:33:58 -0500 |
commit | 3c9d4e9dafdd0918a3539e545cc99646e604757d (patch) | |
tree | 5206bf59ad26698932ca0119b2c04a5f70c88946 /modules | |
parent | c792c7f62df41c48d0d813a809e5415cbefa38b2 (diff) |
Added command aliases
Diffstat (limited to 'modules')
-rw-r--r-- | modules/core/cs_ban.cpp | 7 | ||||
-rw-r--r-- | modules/core/cs_kick.cpp | 7 | ||||
-rw-r--r-- | modules/core/cs_saset.cpp | 2 | ||||
-rw-r--r-- | modules/core/cs_set.cpp | 2 | ||||
-rw-r--r-- | modules/core/ns_identify.cpp | 10 | ||||
-rw-r--r-- | modules/core/ns_saset.cpp | 2 | ||||
-rw-r--r-- | modules/core/ns_set.cpp | 2 | ||||
-rw-r--r-- | modules/core/os_defcon.cpp | 9 | ||||
-rw-r--r-- | modules/extra/m_alias.cpp | 80 | ||||
-rw-r--r-- | modules/extra/m_xmlrpc_main.cpp | 2 |
10 files changed, 97 insertions, 26 deletions
diff --git a/modules/core/cs_ban.cpp b/modules/core/cs_ban.cpp index dd2f9be8d..e39256ef4 100644 --- a/modules/core/cs_ban.cpp +++ b/modules/core/cs_ban.cpp @@ -16,7 +16,7 @@ class CommandCSBan : public Command { public: - CommandCSBan(const Anope::string &cname) : Command(cname, 2, 3) + CommandCSBan(const Anope::string &cname) : Command("BAN", 2, 3) { } @@ -96,16 +96,15 @@ class CommandCSBan : public Command class CSBan : public Module { - CommandCSBan commandcsban, commandcskb; + CommandCSBan commandcsban; public: - CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), commandcsban("BAN"), commandcskb("KB") + CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), commandcsban("BAN") { this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(ChanServ, &commandcsban); - this->AddCommand(ChanServ, &commandcskb); } }; diff --git a/modules/core/cs_kick.cpp b/modules/core/cs_kick.cpp index 66c7c84db..43f3dda80 100644 --- a/modules/core/cs_kick.cpp +++ b/modules/core/cs_kick.cpp @@ -16,7 +16,7 @@ class CommandCSKick : public Command { public: - CommandCSKick(const Anope::string &cname) : Command(cname, 2, 3) + CommandCSKick() : Command("KICK", 2, 3) { } @@ -82,16 +82,15 @@ class CommandCSKick : public Command class CSKick : public Module { - CommandCSKick commandcskick, commandcsk; + CommandCSKick commandcskick; public: - CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), commandcskick("KICK"), commandcsk("K") + CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(ChanServ, &commandcskick); - this->AddCommand(ChanServ, &commandcsk); } }; diff --git a/modules/core/cs_saset.cpp b/modules/core/cs_saset.cpp index 7d50db325..0e485e540 100644 --- a/modules/core/cs_saset.cpp +++ b/modules/core/cs_saset.cpp @@ -45,7 +45,7 @@ class CommandCSSASet : public Command for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; Log(LOG_ADMIN, u, this, ci) << params[1] << " " << cmdparams; - mod_run_cmd(ChanServ, u, c, params[1], cmdparams); + mod_run_cmd(ChanServ, u, c, params[1], cmdparams, false); } else { diff --git a/modules/core/cs_set.cpp b/modules/core/cs_set.cpp index 74c0b9f38..fe37e7ea6 100644 --- a/modules/core/cs_set.cpp +++ b/modules/core/cs_set.cpp @@ -49,7 +49,7 @@ class CommandCSSet : public Command 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, u, c, params[1], cmdparams); + mod_run_cmd(ChanServ, u, c, params[1], cmdparams, false); } else { diff --git a/modules/core/ns_identify.cpp b/modules/core/ns_identify.cpp index ddeca2417..c7748e82c 100644 --- a/modules/core/ns_identify.cpp +++ b/modules/core/ns_identify.cpp @@ -16,7 +16,7 @@ class CommandNSIdentify : public Command { public: - CommandNSIdentify(const Anope::string &cname) : Command(cname, 1, 2) + CommandNSIdentify() : Command("IDENTIFY", 1, 2) { this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } @@ -109,23 +109,21 @@ class CommandNSIdentify : public Command void OnServHelp(User *u) { - if (this->name.equals_ci("IDENTIFY")) - u->SendMessage(NickServ, NICK_HELP_CMD_IDENTIFY); + u->SendMessage(NickServ, NICK_HELP_CMD_IDENTIFY); } }; class NSIdentify : public Module { - CommandNSIdentify commandnsidentify, commandnsid; + CommandNSIdentify commandnsidentify; public: - NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), commandnsidentify("IDENTIFY"), commandnsid("ID") + NSIdentify(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(NickServ, &commandnsidentify); - this->AddCommand(NickServ, &commandnsid); } }; diff --git a/modules/core/ns_saset.cpp b/modules/core/ns_saset.cpp index 624ac2883..f3ca83909 100644 --- a/modules/core/ns_saset.cpp +++ b/modules/core/ns_saset.cpp @@ -60,7 +60,7 @@ class CommandNSSASet : public Command Log(LOG_ADMIN, u, this) << params[1] << " " << cmdparams; else Log(LOG_ADMIN, u, this) << params[1] << " for " << params[0]; - mod_run_cmd(NickServ, u, c, params[1], cmdparams); + mod_run_cmd(NickServ, u, c, params[1], cmdparams, false); } else u->SendMessage(NickServ, NICK_SASET_UNKNOWN_OPTION, cmd.c_str()); diff --git a/modules/core/ns_set.cpp b/modules/core/ns_set.cpp index a297c0918..a8a08d3cb 100644 --- a/modules/core/ns_set.cpp +++ b/modules/core/ns_set.cpp @@ -54,7 +54,7 @@ class CommandNSSet : public Command Log(LOG_COMMAND, u, this) << params[0] << " " << cmdparams; else Log(LOG_COMMAND, u, this) << params[0]; - mod_run_cmd(NickServ, u, c, params[0], cmdparams); + mod_run_cmd(NickServ, u, c, params[0], cmdparams, false); } else u->SendMessage(NickServ, NICK_SET_UNKNOWN_OPTION, params[0].c_str()); diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index 89bc2b6f0..e17a6d33a 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -205,14 +205,9 @@ class OSDefcon : public Module return EVENT_CONTINUE; } - EventReturn OnPreCommandRun(User *u, BotInfo *bi, const Anope::string &command, const Anope::string &message, Command *c) + EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, bool fantasy) { - if (!c) - { - if (CheckDefCon(DEFCON_SILENT_OPER_ONLY) && !is_oper(u)) - return EVENT_STOP; - } - if ((CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY)) && !is_oper(u)) + if (!is_oper(u) && CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY)) { if (!CheckDefCon(DEFCON_SILENT_OPER_ONLY)) u->SendMessage(bi, OPER_DEFCON_DENIED); diff --git a/modules/extra/m_alias.cpp b/modules/extra/m_alias.cpp new file mode 100644 index 000000000..4eac38179 --- /dev/null +++ b/modules/extra/m_alias.cpp @@ -0,0 +1,80 @@ +/* + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" + +struct CommandAlias +{ + bool fantasy; + bool operonly; + Anope::string client; + Anope::string alias; + Anope::string command; +}; + +class ModuleAlias : public Module +{ + std::map<Anope::string, CommandAlias, std::less<ci::string> > aliases; + public: + ModuleAlias(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) + { + Implementation i[] = { I_OnReload, I_OnPreCommandRun }; + ModuleManager::Attach(i, this, 2); + + OnReload(false); + } + + void OnReload(bool) + { + ConfigReader config; + + this->aliases.clear(); + + for (int i = 0; i < config.Enumerate("alias"); ++i) + { + bool fantasy = config.ReadFlag("alias", "fantasy", "no", i); + bool operonly = config.ReadFlag("alias", "operonly", "no", i); + Anope::string client = config.ReadValue("alias", "client", "", i); + Anope::string aliasname = config.ReadValue("alias", "alias", "", i); + Anope::string command = config.ReadValue("alias", "command", "", i); + + if (aliasname.empty() || command.empty()) + continue; + + CommandAlias alias; + alias.fantasy = fantasy; + alias.operonly = operonly; + alias.client = client; + alias.alias = aliasname; + alias.command = command; + + this->aliases.insert(std::make_pair(aliasname, alias)); + } + } + + EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, bool fantasy) + { + std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command); + if (it != aliases.end()) + { + const CommandAlias &alias = it->second; + + if (fantasy != alias.fantasy) + return EVENT_CONTINUE; + else if (!is_oper(u) && alias.operonly) + return EVENT_CONTINUE; + else if (!fantasy && !bi->nick.equals_ci(alias.client)) + return EVENT_CONTINUE; + + command = alias.command; + } + + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(ModuleAlias) diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp index a3062b7ad..1053523b8 100644 --- a/modules/extra/m_xmlrpc_main.cpp +++ b/modules/extra/m_xmlrpc_main.cpp @@ -86,7 +86,7 @@ class MyXMLRPCEvent : public XMLRPCEvent else request->reply("online", "yes"); - mod_run_cmd(bi, *u, command); + mod_run_cmd(bi, *u, command, false); if (created && u) { |