]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add format="" value, at request of Emeric.
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 16 Dec 2006 23:15:50 +0000 (23:15 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 16 Dec 2006 23:15:50 +0000 (23:15 +0000)
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

docs/inspircd.conf.example
src/modules/m_alias.cpp

index 14e7d6b113012c51b309f934a5d5e2a5bd76afd1..bac34bd574b8eebad14fb0e4be0823d1ab6212e1 100644 (file)
 # 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   #
 #                    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     #
 #                    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   #
 #<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
index 7695b6f626143091709999b8a13dc6741a1a323c..55241c278743df51e4daef034688144b8233ed4a 100644 (file)
@@ -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;