Author Topic: Math Chatbot  (Read 2187 times)

How can I get it so when I say "Bob add(or subtract or whatever) number number" then it makes me say "BoB: ANSWER HERE"?

Package the cliencmdchatmessage, strip the numbers from the message, do math, done.

Package the cliencmdchatmessage, strip the numbers from the message, do math, done.
Err, idk how to "Strip the numbers from the message".

Err, idk how to "Strip the numbers from the message".


Well figure out what the equation is going to be using str str and getSubStr

%msg = "bob add 2+2 please";

if(strStr(%msg,"+") <= 0)
{
     //we are adding do math stuff here using getsubstr

}

if you want to make it using order of operations, better check for * and / first.
it wouldn't be perfect order, but it's worth a try.


Well figure out what the equation is going to be using str str and getSubStr

%msg = "bob add 2+2 please";

if(strStr(%msg,"+") <= 0)
{
     //we are adding do math stuff here using getsubstr

}

I've never worked with str or getsubstr and I have no idea how they work or what they do.

I've never worked with str or getsubstr and I have no idea how they work or what they do.
getSubStr takes the first character from the string you input and assigns it to a variable.

no idea what strstr is but i believe it's whether it contains whatever string is inputted in the second argument.

My friend BL_ID 1337 has a math chatbot. But its better than infinite's example. It will add, subtract, multiply, and divide any 2 numbers you give it. It will also say anything you want it to say. He also even has a auto-spell/grammer-fixer

My friend BL_ID 1337 has a math chatbot.
Well he does not have RTB so I guess I may never find out who he is.

My friend BL_ID 1337 has a math chatbot.
BLID 1337 doesn't exist genius.
 
But anyways, on topic, you may want to check who's sending the chat, to make sure other people can't spam it.

BLID 1337 doesn't exist genius.
How was I supposed to know that? D:
But anyways, on topic, you may want to check who's sending the chat, to make sure other people can't spam it.
I already know how :P


BLID 1337 doesn't exist genius.
 
But anyways, on topic, you may want to check who's sending the chat, to make sure other people can't spam it.
Idiot. He does exist. Hes just not online anymore :(

Wrote this really quick and did minimal testing, edit it to your liking..

package mathBot
{
   function clientCmdChatMessage(%a,%b,%c,%d,%pref,%name,%suff,%msg)
   {
      parent::clientCmdChatMessage(%a,%b,%c,%d,%pref,%name,%suff,%msg);
      if($mathbot)
      {
         if(getWord(%msg,0) $= "-math")
         {
            if(isMathQuestion(%msg))
            {
               %answer = returnAnswer(%msg);
               if(%answer)
               {
                  commandToServer('messageSent',"The answer to "@%msg@" is "@%answer@".");
               }
            }
         }
      }
   }
};
activatePackage(mathBot);


function isMathQuestion(%msg)
{
   if(strStr(%msg,"*") <= 0 || strStr(%msg,"/") <= 0 || strStr(%msg,"+") <=0 || strStr(%msg,"-") <= 0)
   {
      return true;
   }

   return false;
}

function returnAnswer(%msg)
{
   %letter = "a b c d e f g h i j k l m n o p q r s t u v w x y z";

   for(%i=0;%i<getWordCount(%letter);%i++)
   {
      %let = getWord(%letter,%i);
      %msg = strReplace(%msg,%let,"");
   }


   eval("%answer = ("@%msg@");");

   return %answer;
}

I know I have a working math chatbot, that includes a .txt file that you can fill with names of people you want to be able to use it, and it will automatically read it and if the person's name is in the .txt, it lets them use it. It's a really efficiant system, but I dont have it with me right now, I can post a bit of it when I get home.