src/parse.c
changeset 15 f19c1f9b4cd3
parent 14 fe8adc56b109
child 16 33245bf7873a
--- a/src/parse.c
+++ b/src/parse.c
@@ -23,6 +23,27 @@
 #define SOURCE_URL "http://largo.homelinux.org/cgi-bin/gitweb.cgi?p=net/mcbot.git"
 #endif
 
+#define    HELP  0
+#define    JOIN  1
+#define   LEAVE  2
+#define     ADD  3
+#define REPLACE  4
+#define  DELETE  5
+#define    LIST  6
+#define  SEARCH  7
+#define    INFO  8
+#define    PING  9
+#define      ON 10
+#define     OFF 11
+#define   DEBUG 12
+#define VACCUUM 13
+#define  LOGOUT 14
+#define     WHO 15
+#define   WHOIS 16
+#define    TIME 17
+#define    TELL 18
+#define      OP 19
+
 const
 char *COMMAND_LIST[] = {
     "!help      Known Commands: join(1), leave(2), add(3), replace(4), delete(5), list(6), search(7), info(8)\r\n",
@@ -43,7 +64,7 @@
 };
 
 const
-char ITEMS = 14;
+char VISIBLE_ITEMS = 14;
 
 const
 char *Bot_Commands[] = {
@@ -111,27 +132,27 @@
     while (Bot_Commands[i]) {
         if (!strcmp (token, Bot_Commands[i])) {
             switch (i) {
-            case 0:            /* !help */
+            case HELP:
                 if ((token = strtok (NULL, "\r\n")))
                     cmd = atoi (token);
-                if ((cmd > 0) && (cmd < ITEMS))
+                if ((cmd > 0) && (cmd < VISIBLE_ITEMS))
                     snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[cmd]);
                 else
                     snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, COMMAND_LIST[0]);
                 return msg;
 
-            case 1:            /* !join */
+            case JOIN:
                 if ((token = strtok (NULL, "\r\n")))
                     snprintf (msg, 512, "JOIN %s\r\n", token);
                 return msg;
 
-            case 2:            /* !leave */
+            case LEAVE:
                 if (*message->channel != '#')
                     return NULL;
                 snprintf (msg, 512, "PART %s :Leaving.\r\n", message->channel);
                 return msg;
 
-            case 3:            /* !add */
+            case ADD:
                 if ((token = strtok (NULL, " "))) {
                     if ((parameters = strtok (NULL, "\r\n"))) {
                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
@@ -143,7 +164,7 @@
                 }
                 return msg;
 
-            case 4:            /* !replace */
+            case REPLACE:
                 if ((token = strtok (NULL, " "))) {
                     if ((parameters = strtok (NULL, "\r\n"))) {
                         snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
@@ -155,7 +176,7 @@
                 }
                 return msg;
 
-            case 5:            /* !delete */
+            case DELETE:
                 if ((token = strtok (NULL, "\r\n"))) {
                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n",
                               message->channel, message->user, db_remove (DATABASE_FILE, token));
@@ -165,12 +186,12 @@
                 }
                 return msg;
 
-            case 6:            /* !count */
+            case LIST:
                 snprintf (msg, 512, "PRIVMSG %s :%s %s\r\n", message->channel, db_elements (DATABASE_FILE),
                           db_lookup (DATABASE_FILE, "mcbot.cgi"));
                 return msg;
 
-            case 7:            /* !search */
+            case SEARCH:
                 if ((token = strtok (NULL, "\r\n"))) {
                     snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", message->channel, message->user,
                               db_lookup (DATABASE_FILE, token));
@@ -181,36 +202,36 @@
                 }
                 return msg;
 
-            case 8:            /* !info */
+            case INFO:
                 snprintf (msg, 512, "PRIVMSG %s :I am MCBot-%1.2f and my source code can be found on %s\r\n",
-                          message->channel, VERSION, SOURCE_URL);
+                          message->channel, BOT_VERSION, SOURCE_URL);
                 return msg;
 
-            case 9:            /* !ping */
+            case PING:
                 if ((token = strtok (NULL, "\r\n")))
                     snprintf (msg, 512, "PRIVMSG %s :PING 0815\r\n", token);
                 return msg;
 
-            case 10:           /* !on */
+            case ON:
                 snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn enabled for channel"),
                           message->channel);
                 return msg;
 
-            case 11:           /* !off */
+            case OFF:
                 snprintf (msg, 512, "PRIVMSG %s :%s %s.\r\n", message->user, gettext ("Autolearn disabled for channel"),
                           message->channel);
                 return msg;
 
-            case 12:           /* !debug */
+            case DEBUG:
                 snprintf (msg, 512, "PRIVMSG %s :USER: %s EMAIL: %s CHANNEL: %s LINE: %s\r\n", message->channel,
                           message->user, message->email, message->channel, message->line);
                 return msg;
 
-            case 13:           /* !vaccum */
+            case VACCUUM:
                 snprintf (msg, 512, "PRIVMSG %s :%s\r\n", message->channel, db_vaccuum (DATABASE_FILE));
                 return msg;
 
-            case 14:           /* !logout */
+            case LOGOUT:
                 if (strstr (message->user, db_lookup (DATABASE_FILE, "mcbot.user"))) {
                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email"))) {
                         snprintf (msg, 512, "PRIVMSG %s :%s!\r\nQUIT\r\n", message->channel,
@@ -222,19 +243,19 @@
                  */
                 return msg;
 
-            case 15:           /* !who */
+            case WHO:
                 if ((token = strtok (NULL, "\r\n")) != NULL) {
                     snprintf (msg, 512, "WHO %s\r\n", token);
                 }
                 return msg;
 
-            case 16:           /* !whois */
+            case WHOIS:
                 if ((token = strtok (NULL, "\r\n")) != NULL) {
                     snprintf (msg, 512, "WHOIS %s\r\n", token);
                 }
                 return msg;
 
-            case 17:           /* time */
+            case TIME:
                 t = time (NULL);
                 timeptr = localtime (&t);
                 if ((token = malloc (81))) {
@@ -245,7 +266,7 @@
                 }
                 return msg;
 
-            case 18:           /* tell */
+            case TELL:
                 if ((token = strtok (NULL, " "))) {
                     if ((parameters = strtok (NULL, "\r\n"))) {
                         if (*token == '*')
@@ -256,7 +277,7 @@
                 }
                 return msg;
 
-            case 19:           /* op */
+            case OP:
                 if ((token = strtok (NULL, "\r\n")) != NULL) {
                     if (strstr (message->email, db_lookup (DATABASE_FILE, "mcbot.email")))
                         snprintf (msg, 512, "MODE %s +o %s\r\n", message->channel, token);