diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-16 23:15:50 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-16 23:15:50 +0000 |
commit | 1eb1b8d92548b16b2b0f48f7404a5dd599fdc03c (patch) | |
tree | 813e6b044e51e71df694098161de405459cbb200 | |
parent | d7bc663d0ad571697f0a022f82aeb4ad3c23cc2b (diff) |
Add format="" value, at request of Emeric.
See: http://www.inspircd.org/forum/index.php/topic,245.0.html
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6019 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | docs/inspircd.conf.example | 34 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 18 |
2 files changed, 47 insertions, 5 deletions
diff --git a/docs/inspircd.conf.example b/docs/inspircd.conf.example index 14e7d6b11..bac34bd57 100644 --- a/docs/inspircd.conf.example +++ b/docs/inspircd.conf.example @@ -880,9 +880,23 @@ # commands to services, however they are not limited to just this use.# # An alias tag requires the following values to be defined in it: # # # -# text - The text to detect at the start of the line, # -# must be at the start of the line to trigger the # -# alias. Cant contain spaces, but case insensitive # +# text - The text to detect as the actual command line, # +# Cant contain spaces, but case insensitive. # +# You may have multiple aliases with the same # +# command name (text="" value), however the first # +# found will be executed if its format value is # +# matched, or it has no format value. Aliases are # +# read from the top of the file to the bottom. # +# # +# format - If this is defined, the parameters of the alias # +# must match this glob pattern. For example if you # +# want the first parameter to start with a # for # +# the alias to be executed, set format="#*" in the # +# alias definition. Note that the :'s which are # +# part of IRC formatted lines will be preserved # +# for matching of this text. This value is # +# optional. # +# # # replace - The text to replace 'text' with. Usually this # # will be "PRIVMSG ServiceName :$2-" or similar. # # You may use the variables $1 through $9 in the # @@ -898,10 +912,12 @@ # commands with \n. If you wish to use the ACTUAL # # characters \ and n together in a line, you must # # use the sequence "\\n". # +# # # requires - If you provide a value for 'requires' this means # # the given nickname MUST be online for the alias # # to successfully trigger. If they are not, then # # the user receives a 'no such nick' 401 numeric. # +# # # uline - Defining this value with 'yes', 'true' or '1' # # will ensure that the user given in 'requires' # # must also be on a u-lined server, as well as # @@ -909,6 +925,7 @@ # online, but not on a u-lined server, then an # # oper-alert is sent out as this is possibly signs # # of a user trying to impersonate a service. # +# # # operonly - Defining this value, with a value of 'yes', '1' # # or true will make the alias oper only. If a non- # # oper attempts to use the alias, it will appear # @@ -920,7 +937,16 @@ #<alias text="NS" replace="PRIVMSG NickServ :$2-" requires="NickServ" uline="yes"> #<alias text="CS" replace="PRIVMSG ChanServ :$2-" requires="ChanServ" uline="yes"> #<alias text="OS" replace="PRIVMSG OperServ :$2-" requires="OperServ" uline="yes" operonly="yes"> -#<alias text="ID" replace="PRIVMSG NickServ :IDENTIFY $3" requires="NickServ" uline="yes"> +# +# An example of using the format value to create an alias with two +# different behaviours depending on the format of the parameters. +# +#<alias text="ID" format="#*" replace="PRIVMSG ChanServ :IDENTIFY $2 $3" +# requires="ChanServ" uline="yes"> +# +#<alias text="ID" replace="PRIVMSG NickServ :IDENTIFY $2" +# requires="NickServ" uline="yes"> +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Alltime module: Shows time on all connected servers at once diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 7695b6f62..55241c278 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -34,11 +34,14 @@ class Alias : public classbase bool uline; /** Requires oper? */ bool operonly; + /** Format that must be matched for use */ + std::string format; }; class ModuleAlias : public Module { private: + /** We cant use a map, there may be multiple aliases with the same name */ std::vector<Alias> Aliases; std::vector<std::string> pars; @@ -57,6 +60,7 @@ class ModuleAlias : public Module a.requires = MyConf.ReadValue("alias", "requires", i); a.uline = MyConf.ReadFlag("alias", "uline", i); a.operonly = MyConf.ReadFlag("alias", "operonly", i); + a.format = MyConf.ReadValue("alias", "format", i); Aliases.push_back(a); } } @@ -127,18 +131,30 @@ class ModuleAlias : public Module virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line) { userrec *u = NULL; - irc::string c = command.c_str(); + /* If the command is valid, we dont want to know, * and if theyre not registered yet, we dont want * to know either */ if ((validated) || (user->registered != REG_ALL)) return 0; + + irc::string c = command.c_str(); + /* The parameters for the command in their original form, with the command stripped off */ + std::string compare = original_line.substr(command.length()); + while (*(compare.c_str()) == ' ') + compare.erase(compare.begin()); for (unsigned int i = 0; i < Aliases.size(); i++) { if (Aliases[i].text == c) { + /* Does it match the pattern? */ + if ((!Aliases[i].format.empty()) && (!ServerInstance->MatchText(compare, Aliases[i].format))) + { + continue; + } + if ((Aliases[i].operonly) && (!*user->oper)) return 0; |