1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 13:36:38 +02:00

Allow command aliases to be redirected to different pseudo clients

This commit is contained in:
Adam
2010-12-06 20:53:15 -05:00
parent aed53dbb47
commit f1d04a2f8e
4 changed files with 53 additions and 40 deletions
+21 -17
View File
@@ -1871,37 +1871,41 @@ m_xmlrpc
module { name = "m_alias" }
alias
{
/* Set to yes to make this alias triggerabe by fantasy commands.
*/
/* Set to yes to make this alias triggerable by fantasy commands. */
fantasy = no
/* Target client the alias should be for (if not using fantasy).
*/
client = "NickServ"
/* Alias name and command */
alias = "ID"
command = "IDENTIFY"
/* Set to yes to make this alias oper only */
operonly = no
/* Source client and command.
*/
source_client = "NickServ"
source_command = "ID"
/* Target client and command.
*/
target_client = "NickServ"
target_command = "IDENTIFY"
}
/* Provides the !k fantasy command */
alias
{
fantasy = true
alias = "K"
command = "KICK"
fantasy = yes
source_command = "K"
target_client = "ChanServ"
target_command = "KICK"
}
/* Provides the !kb fantasy command */
alias
{
fantasy = true
alias = "KB"
command = "BAN"
fantasy = yes
source_command = "KB"
target_client = "ChanServ"
target_command = "BAN"
}
/*
+1 -1
View File
@@ -367,7 +367,7 @@ class CoreExport Module : public Extensible
* @param ci If a tanasy command, the channel the comman was used on
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
virtual EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci) { return EVENT_CONTINUE; }
virtual EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci) { return EVENT_CONTINUE; }
/** Called before a command is due to be executed.
* @param source The source of the command
+1 -1
View File
@@ -206,7 +206,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci)
EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci)
{
if (!u->HasMode(UMODE_OPER) && (CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY)))
{
+30 -21
View File
@@ -11,14 +11,15 @@ struct CommandAlias
{
bool fantasy;
bool operonly;
Anope::string client;
Anope::string alias;
Anope::string command;
Anope::string source_client;
Anope::string source_command;
Anope::string target_client;
Anope::string target_command;
};
class ModuleAlias : public Module
{
std::map<Anope::string, CommandAlias, std::less<ci::string> > aliases;
std::multimap<Anope::string, CommandAlias, std::less<ci::string> > aliases;
public:
ModuleAlias(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
@@ -38,40 +39,48 @@ class ModuleAlias : public Module
{
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);
Anope::string source_client = config.ReadValue("alias", "source_client", "", i);
Anope::string source_command = config.ReadValue("alias", "source_command", "", i);
Anope::string target_client = config.ReadValue("alias", "target_client", "", i);
Anope::string target_command = config.ReadValue("alias", "target_command", "", i);
if (aliasname.empty() || command.empty())
if ((!fantasy &&source_client.empty()) || source_command.empty() || target_client.empty() || target_command.empty())
continue;
CommandAlias alias;
alias.fantasy = fantasy;
alias.operonly = operonly;
alias.client = client;
alias.alias = aliasname;
alias.command = command;
alias.source_client = source_client;
alias.source_command = source_command;
alias.target_client = target_client;
alias.target_command = target_command;
this->aliases.insert(std::make_pair(aliasname, alias));
this->aliases.insert(std::make_pair(source_command, alias));
}
}
EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, ChannelInfo *ci)
EventReturn OnPreCommandRun(User *&u, BotInfo *&bi, Anope::string &command, Anope::string &message, ChannelInfo *&ci)
{
bool fantasy = ci != NULL;
std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command);
if (it != aliases.end())
std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command),
it_end = aliases.upper_bound(command);
for (; it != it_end; ++it)
{
const CommandAlias &alias = it->second;
if (fantasy != alias.fantasy)
return EVENT_CONTINUE;
if (!fantasy && !bi->nick.equals_ci(alias.source_client))
continue;
else if (fantasy != alias.fantasy)
continue;
else if (!u->HasMode(UMODE_OPER) && alias.operonly)
return EVENT_CONTINUE;
else if (!fantasy && !bi->nick.equals_ci(alias.client))
return EVENT_CONTINUE;
continue;
command = alias.command;
BotInfo *target = findbot(alias.target_client);
if (target)
bi = target;
command = alias.target_command;
break;
}
return EVENT_CONTINUE;