src/parse.c
changeset 3 a82a978f23f7
parent 0 586472add385
child 8 3152de03758e
equal deleted inserted replaced
2:6a2e88214b80 3:a82a978f23f7
   133                 if ((token = strtok (NULL, " "))) {
   133                 if ((token = strtok (NULL, " "))) {
   134                     if ((parameters = strtok (NULL, "\r\n"))) {
   134                     if ((parameters = strtok (NULL, "\r\n"))) {
   135                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   135                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   136                                   message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0));
   136                                   message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 0));
   137                     } else {
   137                     } else {
   138                         snprintf (msg, 512,
   138                         snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel,
   139                                   "PRIVMSG %s :%s, %s!\r\n",
   139                                   gettext ("I need more parameters to add"), message->user);
   140                                   message->channel, gettext ("I need more parameters to add"), message->user);
       
   141                     }
   140                     }
   142                 }
   141                 }
   143                 return msg;
   142                 return msg;
   144 
   143 
   145             case 4:            /* !replace */
   144             case 4:            /* !replace */
   146                 if ((token = strtok (NULL, " "))) {
   145                 if ((token = strtok (NULL, " "))) {
   147                     if ((parameters = strtok (NULL, "\r\n"))) {
   146                     if ((parameters = strtok (NULL, "\r\n"))) {
   148                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   147                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   149                                   message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1));
   148                                   message->channel, message->user, db_insert (DATABASE_FILE, token, parameters, 1));
   150                     } else {
   149                     } else {
   151                         snprintf (msg, 512,
   150                         snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel,
   152                                   "PRIVMSG %s :%s, %s!\r\n",
   151                                   gettext ("I need more parameters to replace"), message->user);
   153                                   message->channel, gettext ("I need more parameters to replace"), message->user);
       
   154                     }
   152                     }
   155                 }
   153                 }
   156                 return msg;
   154                 return msg;
   157 
   155 
   158             case 5:            /* !delete */
   156             case 5:            /* !delete */
   159                 if ((token = strtok (NULL, "\r\n"))) {
   157                 if ((token = strtok (NULL, "\r\n"))) {
   160                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   158                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   161                               message->channel, message->user, db_remove (DATABASE_FILE, token));
   159                               message->channel, message->user, db_remove (DATABASE_FILE, token));
   162                 } else {
   160                 } else {
   163                     snprintf (msg, 512,
   161                     snprintf (msg, 512, "PRIVMSG %s :%s, %s!\r\n", message->channel, gettext ("I need a key to delete"),
   164                               "PRIVMSG %s :%s, %s!\r\n",
   162                               message->user);
   165                               message->channel, gettext ("I need a key to delete"), message->user);
       
   166                 }
   163                 }
   167                 return msg;
   164                 return msg;
   168 
   165 
   169             case 6:            /* !count */
   166             case 6:            /* !count */
   170                 snprintf (msg, 512, "PRIVMSG %s :%s %s\r\n", message->channel,
   167                 snprintf (msg, 512, "PRIVMSG %s :%s %s\r\n", message->channel, db_elements (DATABASE_FILE),
   171                           db_elements (DATABASE_FILE), db_lookup(DATABASE_FILE, "mcbot.cgi"));
   168                           db_lookup (DATABASE_FILE, "mcbot.cgi"));
   172                 return msg;
   169                 return msg;
   173 
   170 
   174             case 7:            /* !search */
   171             case 7:            /* !search */
   175                 if ((token = strtok (NULL, "\r\n"))) {
   172                 if ((token = strtok (NULL, "\r\n"))) {
   176                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   173                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", message->channel, message->user,
   177                               message->channel, message->user, db_lookup (DATABASE_FILE, token));
   174                               db_lookup (DATABASE_FILE, token));
   178                 } else {
   175                 } else {
   179                     snprintf (msg, 512,
   176                     snprintf (msg, 512,
   180                               "PRIVMSG %s :%s, %s!\r\n",
   177                               "PRIVMSG %s :%s, %s!\r\n", message->channel, gettext ("I need a key to lookup"),
   181                               message->channel, gettext ("I need a key to lookup"), message->user);
   178                               message->user);
   182                 }
   179                 }
   183                 return msg;
   180                 return msg;
   184 
   181 
   185             case 8:            /* !info */
   182             case 8:            /* !info */
   186                 snprintf (msg, 512,
   183                 snprintf (msg, 512, "PRIVMSG %s :I am MCBot-%1.2f and my source code can be found on %s\r\n",
   187                           "PRIVMSG %s :I am MCBot-%1.2f and my source code can be found on %s\r\n",
       
   188                           message->channel, VERSION, "http://largo.homelinux.org/svn/c/mcbot/trunk");
   184                           message->channel, VERSION, "http://largo.homelinux.org/svn/c/mcbot/trunk");
   189                 return msg;
   185                 return msg;
   190 
   186 
   191             case 9:            /* !ping */
   187             case 9:            /* !ping */
   192                 if ((token = strtok (NULL, "\r\n")))
   188                 if ((token = strtok (NULL, "\r\n")))
   193                     snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token);
   189                     snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token);
   194                 return msg;
   190                 return msg;
   195 
   191 
   196             case 10:           /* !on */
   192             case 10:           /* !on */
   197                 snprintf (msg, 512,
   193                 snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn enabled for channel"),
   198                           "PRIVMSG %s :%s %s.\r\n",
   194                           message->channel);
   199                           message->user, gettext ("Autolearn enabled for channel"), message->channel);
       
   200                 return msg;
   195                 return msg;
   201 
   196 
   202             case 11:           /* !off */
   197             case 11:           /* !off */
   203                 snprintf (msg, 512,
   198                 snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn disabled for channel"),
   204                           "PRIVMSG %s :%s %s.\r\n",
   199                           message->channel);
   205                           message->user, gettext ("Autolearn disabled for channel"), message->channel);
       
   206                 return msg;
   200                 return msg;
   207 
   201 
   208             case 12:           /* !debug */
   202             case 12:           /* !debug */
   209                 snprintf (msg, 512,
   203                 snprintf (msg, 512, "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n", message->channel,
   210                           "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n",
   204                           message->user, message->email, message->channel, message->line);
   211                           message->channel, message->user, message->email, message->channel, message->line);
       
   212                 return msg;
   205                 return msg;
   213 
   206 
   214             case 13:           /* !vaccum */
   207             case 13:           /* !vaccum */
   215                 snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE));
   208                 snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE));
   216                 return msg;
   209                 return msg;
   217 
   210 
   218             case 14:           /* !logout */
   211             case 14:           /* !logout */
   219                 if (strstr (message->user, db_lookup(DATABASE_FILE, "mcbot.user"))) {
   212                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
   220                     if (strstr (message->email, db_lookup(DATABASE_FILE, "mcbot.email"))) {
   213                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) {
   221                         snprintf (msg, 512,
   214                         snprintf (msg, 512, "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel,
   222                                   "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel, gettext ("Bye, have a nice day!"));
   215                                   gettext ("Bye, have a nice day!"));
   223                         *active = 0;
   216                         *active = 0;
   224                     }
   217                     }
   225                 }
   218                 }
   226                 /*
   219                 /*
   227                  * the returned message is either the default one or the generated one
   220                  * the returned message is either the default one or the generated one
   231             case 15:           /* !who */
   224             case 15:           /* !who */
   232                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   225                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   233                     snprintf (msg, 512, "WHO %s\r\n", token);
   226                     snprintf (msg, 512, "WHO %s\r\n", token);
   234                 }
   227                 }
   235                 return msg;
   228                 return msg;
   236                 break;
       
   237 
   229 
   238             case 16:           /* !whois */
   230             case 16:           /* !whois */
   239                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   231                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   240                     snprintf (msg, 512, "WHOIS %s\r\n", token);
   232                     snprintf (msg, 512, "WHOIS %s\r\n", token);
   241                 }
   233                 }
   242                 return msg;
   234                 return msg;
   243                 break;
   235 
   244             case 17:           /* time */
   236             case 17:           /* time */
   245                 t = time (NULL);
   237                 t = time (NULL);
   246                 timeptr = localtime (&t);
   238                 timeptr = localtime (&t);
   247                 if ((token = malloc (81))) {
   239                 if ((token = malloc (81))) {
   248                     strftime (token, 80, "%I:%M:%S %p", timeptr);
   240                     strftime (token, 80, "%I:%M:%S %p", timeptr);
   249                     snprintf (msg, 512, "PRIVMSG %s :%s %s, %s!\r\n",
   241                     snprintf (msg, 512, "PRIVMSG %s :%s %s, %s!\r\n", message->channel, gettext ("It is"), token,
   250                               message->channel, gettext ("It is"), token, message->user);
   242                               message->user);
   251                     free (token);
   243                     free (token);
   252                 }
   244                 }
   253                 return msg;
   245                 return msg;
   254                 break;
   246 
   255             case 18:           /* tell */
   247             case 18:           /* tell */
   256                 if ((token = strtok (NULL, " "))) {
   248                 if ((token = strtok (NULL, " "))) {
   257                     if ((parameters = strtok (NULL, "\r\n"))) {
   249                     if ((parameters = strtok (NULL, "\r\n"))) {
   258                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   250                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
   259                                   (*token ==
   251                                   ('*' == *token) ? ++token : message->channel, token, db_lookup (DATABASE_FILE,
   260                                    '*') ? ++token : message->channel, token, db_lookup (DATABASE_FILE, parameters));
   252                                                                                                   parameters));
   261                     }
   253                     }
   262                 }
   254                 }
   263                 return msg;
   255                 return msg;
   264                 break;
   256 
   265             case 19:           /* op */
   257             case 19:           /* op */
   266                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   258                 if ((token = strtok (NULL, "\r\n")) != NULL) {
   267                     if (strstr (message->email, db_lookup(DATABASE_FILE, "mcbot.email")))
   259                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
   268                         snprintf (msg, 512, "MODE %s +o %s\r\n", message->channel, token);
   260                         snprintf (msg, 512, "MODE %s +o %s\r\n", message->channel, token);
   269                 }
   261                 }
   270                 return msg;
   262                 return msg;
   271                 break;
       
   272             }
   263             }
   273         }
   264         }
   274         i++;
   265         i++;
   275     }
   266     }
   276 
   267