src/parse.c
changeset 23 1cd79bb84e9c
parent 22 b786b5f92a93
child 31 bbcb8a3366b4
equal deleted inserted replaced
22:b786b5f92a93 23:1cd79bb84e9c
    46 #define    DEOP 20
    46 #define    DEOP 20
    47 #define    KICK 21
    47 #define    KICK 21
    48 #define     BAN 22
    48 #define     BAN 22
    49 #define   UNBAN 23
    49 #define   UNBAN 23
    50 #define KICKBAN 24
    50 #define KICKBAN 24
       
    51 #define   HELLO 25
    51 
    52 
    52 const
    53 const
    53 char *COMMAND_LIST[] = {
    54 char *COMMAND_LIST[] = {
    54     "help      Known Commands: join(1), leave(2), add(3), replace(4), delete(5), list(6), search(7), info(8)\r\n",
    55     "help      Known Commands: join(1), leave(2), add(3), replace(4), delete(5), list(6), search(7), info(8)\r\n",
    55     "join:     Joins a new channel\r\n",
    56     "join:     Joins a new channel\r\n",
    80     "!ping", "!on", "!off",
    81     "!ping", "!on", "!off",
    81     "!debug", "!vaccuum", "!logout",
    82     "!debug", "!vaccuum", "!logout",
    82     "!who", "!whois", "!time",
    83     "!who", "!whois", "!time",
    83     "!tell", "!op", "!deop",
    84     "!tell", "!op", "!deop",
    84     "!kick", "!ban", "!unban",
    85     "!kick", "!ban", "!unban",
    85     "!kickban",
    86     "!kickban", "!hello",
    86     NULL
    87     NULL
    87 };
    88 };
    88 
    89 
    89 char *parse (MSG * message)
    90 char *parse (MSG * message)
    90 {
    91 {
    94     char *token;
    95     char *token;
    95     char *parameters;
    96     char *parameters;
    96 
    97 
    97     time_t t;
    98     time_t t;
    98     struct tm *timeptr;
    99     struct tm *timeptr;
    99     static int counter = 0;
       
   100 
   100 
   101     /*
   101     /*
   102      * default message
   102      * default message
   103      */
   103      */
   104     snprintf (msg, 512, "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed"));
   104     snprintf (msg, 512, "PRIVMSG %s :%s.\r\n", message->channel, gettext ("Request cannot be performed"));
   106     /*
   106     /*
   107      * PRIVATE MESSAGES
   107      * PRIVATE MESSAGES
   108      */
   108      */
   109     if (!strcmp (message->channel, message->nick))
   109     if (!strcmp (message->channel, message->nick))
   110         message->channel = message->user;
   110         message->channel = message->user;
   111 
       
   112     if (strstr (message->line, message->nick)) {
       
   113         if (*message->line != '!') {
       
   114             /*
       
   115              * DEADLOCK-CHECK
       
   116              */
       
   117             if (strcmp (message->user, message->nick)) {
       
   118                 snprintf (msg, 512, "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"), message->user);
       
   119                 if (counter++ > 2)
       
   120                     return NULL;
       
   121                 return msg;
       
   122             }
       
   123         }
       
   124         return NULL;
       
   125     }
       
   126 
       
   127     counter = 0;
       
   128 
   111 
   129     /*
   112     /*
   130      * NO BOT Commands
   113      * NO BOT Commands
   131      */
   114      */
   132     if (*message->line != '!') {
   115     if (*message->line != '!') {
   213                               message->user);
   196                               message->user);
   214                 }
   197                 }
   215                 return msg;
   198                 return msg;
   216 
   199 
   217             case INFO:
   200             case INFO:
   218                 snprintf (msg, 512, "PRIVMSG %s :I am MCBot-%1.2f and my source code can be found on %s\r\n",
   201                 snprintf (msg, 512, "PRIVMSG %s :I am MCBot-%1.2f Build %s and my source code can be found at %s\r\n",
   219                           message->channel, BOT_VERSION, SOURCE_URL);
   202                           message->channel, BOT_VERSION, BOT_BUILD, SOURCE_URL);
   220                 return msg;
   203                 return msg;
   221 
   204 
   222             case PING:
   205             case PING:
   223                 if ((token = strtok (NULL, "\r\n")))
   206                 if ((token = strtok (NULL, "\r\n")))
   224                     snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token);
   207                     snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token);
   341                             snprintf (msg, 512, "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token,
   324                             snprintf (msg, 512, "MODE %s +b %s\r\nKICK %s %s\r\n", message->channel, token,
   342                                       message->channel, token);
   325                                       message->channel, token);
   343                     }
   326                     }
   344                 }
   327                 }
   345                 return msg;
   328                 return msg;
       
   329 
       
   330             case HELLO:
       
   331                 snprintf (msg, 512, "PRIVMSG %s :%s, %s?\r\n", message->channel, gettext ("What's up"), message->user);
       
   332                 return msg;
   346             }
   333             }
   347         }
   334         }
   348         i++;
   335         i++;
   349     }
   336     }
   350 
   337