]> jfr.im git - irc/evilnet/x3.git/commitdiff
Bunch of toy fixes and updates incluing calc and 8ball.
authorrubinlinux <redacted>
Tue, 26 Jul 2005 20:45:22 +0000 (20:45 +0000)
committerrubinlinux <redacted>
Tue, 26 Jul 2005 20:45:22 +0000 (20:45 +0000)
ChangeLog.X3
src/chanserv.c
src/chanserv.help
src/math.c
x3.conf.example

index 5c18bc34e924f2d7b3636ba42504b80ee3cceecb..e9d710ce48cb3c11695773571d5020193f80fe54 100644 (file)
@@ -1,6 +1,16 @@
 /***********************************************************************
  X3 ChangeLog
 
+2005-07-26  Alex Schumann  <rubin@afternet.org>
+
+       * src/chanserv.c: ported x2's 8ball in, and improved it.
+
+       * src/math.c: Added osiris' hack to do_math for supporting
+       2(10)  and 2pi etc. Improved it to handle pi2 also.
+
+       * src/chanserv.help: updated 8ball help and added 'myaccess' to
+       information help index.
+
 2005-07-18  Alex Schumann  <rubin@afternet.org>
 
        * src/proto-p10.c: added +L awareness
index edf0d48ea8f8c255b176f84ca0f64d14813d1731..ec6aa80cf52561d0600a6bcf580b61bf7a111b57 100644 (file)
@@ -6172,6 +6172,7 @@ static CHANSERV_FUNC(cmd_wut)
     return 1;
 }
 
+#ifdef lame8ball
 static CHANSERV_FUNC(cmd_8ball)
 {
     unsigned int i, j, accum;
@@ -6194,6 +6195,169 @@ static CHANSERV_FUNC(cmd_8ball)
     return 1;
 }
 
+#else /* Use cool 8ball instead */
+
+void eightball(char *outcome, int method, unsigned int seed)
+{
+   int answer = 0;
+
+#define NUMOFCOLORS 18
+   char ballcolors[50][50] = {"blue", "red", "green", "yellow",
+        "white", "black", "grey", "brown",
+        "yellow", "pink", "purple", "orange", "teal", "burgandy",
+        "fuchsia","turquoise","magenta", "cyan"};
+#define NUMOFLOCATIONS 50
+   char balllocations[50][55] = { 
+       "Locke's house", "Oregon", "California", "Indiana", "Canada",
+        "Russia", "Japan", "Florida", "the Bahamas", "Hiroshima",
+        "the Caribbean", "the Everglades", "your head", "your pants", "your school",
+        "the Statue of Liberty", "Mt. Fugi", "your mother's house", "IRC", "OSU",
+        "Locke's cat", "the closet", "the washroom", "the lake", "Spain",
+        "the bathtub", "the toilet", "the sewer", "a horse", "Jupiter",
+        "Uranus", "Pluto", "a dark place", "your undies", "your shirt",
+        "your bra", "your hair", "your bed", "the couch", "the wall", 
+       "Reed", "here --> [X]", "your brain", "Italy", "the Netherlands", 
+       "Mars", "my hardware", "the bar", "Neverland Ranch", "Germany" };
+#define NUMOFPREPS 15
+   char ballpreps[50][50] = { 
+       "Near", "Somewhere near", "In", "In", "In", 
+       "In", "Hiding in", "Under", "Next to", "Over", 
+       "Crying in", "Right beside", "Nowhere near", "North of", "Trying to find"};
+#define NUMOFNUMS 34
+   char ballnums[50][50] = { 
+        "A hundred", "A thousand", "A few", "42",
+        "About 1", "About 2", "About 3", "About 4", "About 5", "About 6", "About 7", "About 8", "About 9", "About 10",
+        "1", "2", "3", "4", "5", "6", "7", "8", "9", "Ten",
+        "1", "2", "3", "4", "5", "6", "7", "8", "9", "Ten",
+        };
+#define NUMOFMULTS 8
+   char ballmults[50][50] = { " million", " or so", " thousand", "", " or less", " or more", "", ""};
+
+   /* Method:
+    * 0: normal  (Not used in x3)
+    * 1: color
+    * 2: where is
+    * 3: how many
+    */
+
+    srand(seed);
+    if (method == 1) /* A Color */
+    {
+      char tmp[MAXLEN];
+
+      answer = (rand() % 12); /* Make sure this is the # of entries */
+      switch(answer)
+      {
+        case 0: strcpy(tmp, "Very bright %s, I'd say.");
+                break;
+        case 1: strcpy(tmp, "Sort of a light %s color.");
+                break;
+        case 2: strcpy(tmp, "Dark and dreary %s.");
+                break;
+        case 3: strcpy(tmp, "Quite a pale shade of %s.");
+                break;
+        case 4: strcpy(tmp, "A gross kind of mucky %s.");
+                break;
+        case 5: strcpy(tmp, "Brilliant whiteish %s.");
+               break;
+       case 6: case 7: case 8: case 9: strcpy(tmp, "%s.");
+               break;
+       case 10: strcpy(tmp, "Solid %s.");
+               break;
+       case 11: strcpy(tmp, "Transparent %s.");
+                break;
+        default: strcpy(outcome, "An invalid random number was generated.");
+                return;
+      }
+      sprintf(outcome, tmp, ballcolors[rand() % NUMOFCOLORS]);
+      return;
+    }
+    else if (method == 2)  /* Location */
+    {
+       sprintf(outcome, "%s %s.", ballpreps[rand() % NUMOFPREPS], balllocations[rand() % NUMOFLOCATIONS]);
+    }
+    else if (method == 3)  /* Number of ___ */
+    {
+       sprintf(outcome, "%s%s.", ballnums[rand() % NUMOFNUMS], ballmults[rand() % NUMOFMULTS]);
+    }
+    else
+    {
+      //Debug(DBGWARNING, "Error in 8ball.");
+    }
+    return;
+}
+
+static CHANSERV_FUNC(cmd_8ball)
+{
+  char *word1, *word2, *word3;
+  static char eb[MAXLEN];
+  unsigned int accum, i, j;
+
+  REQUIRE_PARAMS(1);
+  accum = 0;
+  for(i=1; i<argc; i++)
+    for(j=0; argv[i][j]; j++)
+      accum = (accum << 5) - accum + toupper(argv[i][j]);
+
+  accum += time(NULL)/3600;
+  word1 = argv[1];
+  word2 = argc>2?argv[2]:"";
+  word3 = argc>3?argv[3]:"";
+
+/*** COLOR *****/
+  if((word2) && strcasecmp(word1, "what") == 0 && strcasecmp(word2, "color") == 0)
+     eightball(eb, 1, accum);
+  else if((word3) && strcasecmp(word1, "what's") == 0 && strcasecmp(word2, "the") == 0 && strcasecmp(word3, "color") == 0)
+     eightball(eb, 1, accum);
+  else if((word3) && strcasecmp(word1, "whats") == 0 && strcasecmp(word2, "the") == 0 && strcasecmp(word3, "color") == 0)
+     eightball(eb, 1, accum);
+/*** LOCATION *****/
+  else if(
+           (
+             word2 &&
+             (
+                (strcasecmp(word1, "where") == 0) &&
+                (strcasecmp(word2, "is") == 0)
+             )
+           ) ||
+             (
+                   strcasecmp(word1, "where's") == 0
+             )
+         )
+     eightball(eb, 2, accum);
+/*** NUMBER *****/
+  else if((word2) && strcasecmp(word1, "how") == 0 && strcasecmp(word2, "many") == 0)
+     eightball(eb, 3, accum);
+/*** GENERIC *****/
+  else
+  {
+     /* Generic 8ball question.. so pull from x3.conf srvx style */
+           const char *resp;
+
+           resp = chanserv_conf.eightball->list[accum % chanserv_conf.eightball->used];
+           if(channel)
+           {
+               char response[MAXLEN];
+               sprintf(response, "\002%s\002: %s", user->nick, resp);
+               irc_privmsg(cmd->parent->bot, channel->name, response);
+           }
+           else
+               send_message_type(4, user, cmd->parent->bot, "%s", resp);
+           return 1;
+  }
+
+  if(channel)
+  {
+        char response[MAXLEN];
+        sprintf(response, "\002%s\002: %s", user->nick, eb);
+        irc_privmsg(cmd->parent->bot, channel->name, response);
+  }
+  else
+        send_message_type(4, user, cmd->parent->bot, "%s", eb);
+  return 1;
+}
+#endif
+
 static CHANSERV_FUNC(cmd_d)
 {
     unsigned long sides, count, modifier, ii, total;
index 940d38d48426c5edb1aa07793294abfb1cfc6f99..302d1fbb2ae6dd6625c9f4fdef3ede4f79b3d3dc 100644 (file)
@@ -95,6 +95,7 @@
             " $bEVENTS$b      View a list of events relevant to a channel."
 );
 "INFORMATION"     ("$bInformative Commands:$b",
+            " $bMYACCESS$b    Show all the channels you have access to.",
             " $bVERSION$b     Check the current running version of $C.",
             " $bNETINFO$b     Check current network-wide information.",
             " $bSTAFF$b       Get a list of all the current staff.",
         "For example: CALC sqrt [5 + .43 * (tan[75])] / 2",
         "If you do not have access in the channel, the answer may be reported",
         "to you privately (via MSG or NOTICE) instead of in the channel.",
-        "CALC can be used by all users.",
         "$uSee Also:$u dice, 8ball");
+"8BALL" ("/msg $C 8BALL [yes no question|what color is..|how many..|where is..]?",
+       "8BALL answers yes or no questions, color queistions, numerical questions, and location questions.",
+       "If you do not have access in the channel, the answer may be reported to you privately instead of in the channel.",
+       "$uSee Also:$u dice, calc");
 "CLIST" ("/msg $C CLIST <#channel> [mask]",
         "This command lists all users of level $bCoowner$b on a channel's userlist. If a mask is supplied, only coowners matching the mask will be shown.",
         "$uSee Also:$u addcoowner, delcoowner, mdelcoowner, users");
index bac982033094cabd6b5b0d21fb97d833a5201922..941f70667a543eadbda9426e816c1d30b79f4bd6 100644 (file)
@@ -125,6 +125,81 @@ void do_math(char *Buffer, char *Math)
        int Index;
        int OEndExpected;
 
+
+         /* This is a HACK to insert * before ( so multiplication takes place
+          * in things such as 3(3) instead of ignoring the first 3. Submitted
+          * by Osiris.
+          * I spent some time tlooking at calc.c and I didnt see an easy way
+          * to do this there... and that file gives me a headache.. so.. -Rubin
+          */
+         char newMath[MAXLEN];
+         char *ptr;
+         char lastNumber = false;
+         char lastBracket = false;
+
+
+         ptr = newMath;
+         while(*Math && ptr < newMath+MAXLEN-1)
+         {
+             switch(*Math)
+             {
+               case '1': case '2':
+               case '3': case '4':
+               case '5': case '6':
+               case '7': case '8':
+               case '9': case '0':
+                 lastNumber = true;
+                 if(lastBracket == true)
+                 {
+                     *ptr = '*';
+                     ptr++;
+                 }
+                 *ptr = *Math;
+                 lastBracket = false;
+                 break;
+               case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': 
+                case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': 
+                case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': 
+                case 'v': case 'w': case 'x': case 'y': case 'z': 
+               case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': 
+                case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': 
+                case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': 
+                case 'V': case 'W': case 'X': case 'Y': case 'Z': 
+                 case ')': case ']': /* Support sin[12](3) also */
+                 lastNumber = true;
+                 lastBracket = true;
+                 *ptr = *Math;
+                 break;
+               case '(': case '[':
+                 if (lastNumber == true)
+                 {
+                   *ptr = '*';
+                   ptr++;
+                 }
+                 *ptr = *Math;
+                 lastNumber = false;
+                 lastBracket = false;
+                 break;
+               default:
+                 if(isalpha(*Math))
+                 {
+                   if(lastNumber == true)
+                   {
+                     *ptr = '*';
+                     ptr++;
+                   }
+                 }
+                 *ptr = *Math;
+                 lastNumber = false;
+                 lastBracket = false;
+                 break;
+             }
+             Math++;
+             ptr++;
+           }
+           *ptr = '\0';
+           Math = newMath;
+
        if (!(List = ListFirst = malloc(sizeof(struct MathToken)))) goto MemError;
        if (!(Stack = StackFirst = malloc(sizeof(struct MathToken)))) goto MemError;
        if (!(PostFix = PostFixFirst = malloc(sizeof(struct MathToken)))) goto MemError;
index 4a04bf9b3e0e77892d39dc77f3f7a1e625289eff..771a7e5c7a7076a771e5f29a3a8b13810dcd392f 100644 (file)
         "set_shows" ("DefaultTopic", "TopicMask", "Greeting", "UserGreeting", "Modes", "PubCmd", "InviteMe", "StrictOp", "AutoOp", "EnfModes", "EnfTopic", "TopicSnarf", "UserInfo", "GiveVoice", "GiveOps", "EnfOps", "Setters", "CtcpUser", "CtcpReaction", "Protect", "Toys", "DynLimit", "NoDelete");
  
         // A list of !8ball responses
-        "8ball" ("Not a chance.",
-                "In your dreams.",
+        "8ball" (
+                "Are you out of your MIND?",
+                "It won't happen, not a chance, definitely no.",
+                "Outlook seems bleak.",
+                "My sources say no.",
+                "You bet!",
+                "It is decidedly so.",
+                "It's hard to be sure.",
+                "Most definitely.",
+                "In your dreams...",
+                "If the prophets wish it...",
+                "Forecast hazy, try again later.",
+                "I don't know!",
                 "Absolutely!",
-                "Could be, could be.");
+                "Never.",
+                "Yes.",
+                "No.",
+                "Maybe.");
         // channel(s) that support helpers must be in to be helping
         // if this is a list, any one by itself will do
         "support_channel" ("#support", "#registration");