mirror of
https://github.com/anope/anope.git
synced 2026-06-28 04:36:37 +02:00
Added command aliases
This commit is contained in:
@@ -1838,3 +1838,44 @@ m_xmlrpc
|
||||
*/
|
||||
#module { name = "m_xmlrpc_main" }
|
||||
|
||||
/*
|
||||
* m_alias
|
||||
*
|
||||
* Allows you to create custom command aliases.
|
||||
*/
|
||||
module { name = "m_alias" }
|
||||
alias
|
||||
{
|
||||
/* Set to yes to make this alias triggerabe 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
|
||||
}
|
||||
|
||||
/* Provides the !k fantasy command */
|
||||
alias
|
||||
{
|
||||
fantasy = true
|
||||
alias = "K"
|
||||
command = "KICK"
|
||||
|
||||
}
|
||||
|
||||
/* Provides the !kb fantasy command */
|
||||
alias
|
||||
{
|
||||
fantasy = true
|
||||
alias = "KB"
|
||||
command = "BAN"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -30,8 +30,8 @@ enum CommandReturn
|
||||
|
||||
extern CoreExport Command *FindCommand(BotInfo *bi, const Anope::string &cmd);
|
||||
extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd);
|
||||
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message);
|
||||
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message);
|
||||
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message, bool fantasy);
|
||||
extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, bool fantasy);
|
||||
|
||||
enum CommandFlag
|
||||
{
|
||||
|
||||
+2
-2
@@ -365,10 +365,10 @@ class CoreExport Module : public Extensible
|
||||
* @param bi The bot the command is being run from
|
||||
* @param command The command
|
||||
* @param message The parameters used for the command
|
||||
* @param c The command class (if it exists)
|
||||
* @param fantasy true if this is a fantasy command
|
||||
* @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, const Anope::string &command, const Anope::string &message, Command *c) { return EVENT_CONTINUE; }
|
||||
virtual EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, bool fantasy) { return EVENT_CONTINUE; }
|
||||
|
||||
/** Called before a command is due to be executed.
|
||||
* @param u The user executing the command
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
+19
-16
@@ -320,37 +320,40 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf)
|
||||
if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == Config->BSFantasyCharacter[0] && !was_action)
|
||||
{
|
||||
spacesepstream sep(buf);
|
||||
Anope::string token;
|
||||
Anope::string command;
|
||||
|
||||
if (sep.GetToken(token) && token[0] == Config->BSFantasyCharacter[0])
|
||||
if (sep.GetToken(command) && command[0] == Config->BSFantasyCharacter[0])
|
||||
{
|
||||
/* Strip off the fantasy character */
|
||||
token.erase(token.begin());
|
||||
command.erase(command.begin());
|
||||
|
||||
if (check_access(u, ci, CA_FANTASIA))
|
||||
{
|
||||
Command *command = FindCommand(ChanServ, token);
|
||||
Anope::string message = sep.GetRemaining();
|
||||
|
||||
/* Command exists and can not be called by fantasy */
|
||||
if (command && !command->HasFlag(CFLAG_DISABLE_FANTASY))
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, ci->bi, command, message, true));
|
||||
if (MOD_RESULT == EVENT_STOP)
|
||||
return;
|
||||
|
||||
Command *cmd = FindCommand(ChanServ, command);
|
||||
|
||||
/* Command exists and can be called by fantasy */
|
||||
if (cmd && !cmd->HasFlag(CFLAG_DISABLE_FANTASY))
|
||||
{
|
||||
Anope::string bbuf = token;
|
||||
|
||||
/* Some commands don't need the channel name added.. eg !help */
|
||||
if (!command->HasFlag(CFLAG_STRIP_CHANNEL))
|
||||
bbuf += " " + ci->name;
|
||||
if (!cmd->HasFlag(CFLAG_STRIP_CHANNEL))
|
||||
message = ci->name + " " + message;
|
||||
message = command + " " + message;
|
||||
|
||||
if (!sep.StreamEnd())
|
||||
bbuf += " " + sep.GetRemaining();
|
||||
|
||||
mod_run_cmd(ChanServ, u, bbuf);
|
||||
mod_run_cmd(ChanServ, u, message, true);
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(token, u, ci, sep.GetRemaining()));
|
||||
FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(command, u, ci, sep.GetRemaining()));
|
||||
}
|
||||
else
|
||||
{
|
||||
FOREACH_MOD(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(token, u, ci, sep.GetRemaining()));
|
||||
FOREACH_MOD(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(command, u, ci, sep.GetRemaining()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-14
@@ -26,26 +26,32 @@ Command *FindCommand(BotInfo *bi, const Anope::string &name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message)
|
||||
{
|
||||
spacesepstream sep(message);
|
||||
Anope::string cmd;
|
||||
|
||||
if (sep.GetToken(cmd))
|
||||
mod_run_cmd(bi, u, FindCommand(bi, cmd), cmd, sep.GetRemaining());
|
||||
}
|
||||
|
||||
void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message)
|
||||
void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, bool fantasy)
|
||||
{
|
||||
if (!bi || !u)
|
||||
return;
|
||||
|
||||
spacesepstream sep(fullmessage);
|
||||
Anope::string command, message;
|
||||
|
||||
CommandReturn ret = MOD_CONT;
|
||||
|
||||
if (!sep.GetToken(command))
|
||||
return;
|
||||
message = sep.GetRemaining();
|
||||
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, message, c));
|
||||
FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, message, fantasy));
|
||||
if (MOD_RESULT == EVENT_STOP)
|
||||
return;
|
||||
|
||||
Command *c = FindCommand(bi, command);
|
||||
|
||||
mod_run_cmd(bi, u, c, command, message, fantasy);
|
||||
}
|
||||
|
||||
void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, bool fantasy)
|
||||
{
|
||||
if (!bi || !u)
|
||||
return;
|
||||
|
||||
if (!c)
|
||||
{
|
||||
@@ -88,6 +94,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command,
|
||||
return;
|
||||
}
|
||||
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->service, c->name, params));
|
||||
if (MOD_RESULT == EVENT_STOP)
|
||||
return;
|
||||
@@ -134,7 +141,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command,
|
||||
return;
|
||||
}
|
||||
|
||||
ret = c->Execute(u, params);
|
||||
CommandReturn ret = c->Execute(u, params);
|
||||
|
||||
if (ret == MOD_CONT)
|
||||
{
|
||||
|
||||
+4
-4
@@ -175,20 +175,20 @@ int m_privmsg(const Anope::string &source, const Anope::string &receiver, const
|
||||
}
|
||||
}
|
||||
if (bi == NickServ || bi == MemoServ || bi == BotServ)
|
||||
mod_run_cmd(bi, u, message);
|
||||
mod_run_cmd(bi, u, message, false);
|
||||
else if (bi == ChanServ)
|
||||
{
|
||||
if (!is_oper(u) && Config->CSOpersOnly)
|
||||
u->SendMessage(ChanServ, ACCESS_DENIED);
|
||||
else
|
||||
mod_run_cmd(bi, u, message);
|
||||
mod_run_cmd(bi, u, message, false);
|
||||
}
|
||||
else if (bi == HostServ)
|
||||
{
|
||||
if (!ircd->vhost)
|
||||
u->SendMessage(HostServ, SERVICE_OFFLINE, Config->s_HostServ.c_str());
|
||||
else
|
||||
mod_run_cmd(bi, u, message);
|
||||
mod_run_cmd(bi, u, message, false);
|
||||
}
|
||||
else if (bi == OperServ)
|
||||
{
|
||||
@@ -201,7 +201,7 @@ int m_privmsg(const Anope::string &source, const Anope::string &receiver, const
|
||||
else
|
||||
{
|
||||
Log(OperServ) << u->nick << ": " << message;
|
||||
mod_run_cmd(bi, u, message);
|
||||
mod_run_cmd(bi, u, message, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user