document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //-----------------------
  2. //The name of our chatbot
  3. //-----------------------
  4. $chatBot::name = "Bob";
  5.  
  6. //-------------------------------------------------------------
  7. //Our Chatbot\'s Responses, anything that uses multiple
  8. //Words should instead use an underscore "_" instead of a space
  9. //Users can constantly add new keywords to respond to
  10. //-------------------------------------------------------------
  11. $chatBot::response["Hi"] = "Hi Hey What\'s_up Heya Howdy";
  12. $chatBot::response["Lol"] = "What\'s_So_Funny? Haha_I_don\'t_get_it... That\'s_not_funny";
  13.  
  14. //--------------------------------------------------------
  15. //Number of milliseconds that our chatbot will not respond
  16. //After having responded to any phrase at all
  17. //--------------------------------------------------------
  18. $chatBot::timeOut = 5000;
  19.  
  20.  
  21. package myFirstChatBot
  22. {
  23.     //---------------------------------------------------------
  24.     //There are only a few parameters we need to focus on here
  25.     //Which are %name and %msg
  26.     //---------------------------------------------------------
  27.    
  28.     function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
  29.     {
  30.         parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
  31.        
  32.         //We want to ignore our name
  33.         if(%name !$= $pref::Player::NetName)
  34.         {
  35.             //Strip things we dont want
  36.             %msg = stripMlControlChars(%msg);
  37.            
  38.             %hasTrigger = chatBot_messageHasTriggerWord(%msg);
  39.            
  40.             if(%hasTrigger !$= "0")
  41.             {
  42.                 %phrase = chatBot_getRandomPhraseFromWord(%hasTrigger);
  43.                 chatBot_say(%phrase);
  44.             }
  45.         }
  46.     }
  47. };
  48. activatePackage(myFirstChatBot);
  49.  
  50. //----------------------------------------------
  51. //This function picks one of our random phrases
  52. //And returns it so we can use it
  53. //----------------------------------------------
  54.  
  55. function chatBot_getRandomPhraseFromWord(%word)
  56. {
  57.     %phrases = $chatBot::response[%word];
  58.    
  59.     if(%phrases !$= "")
  60.     {
  61.         %count = getWordCount(%phrases);
  62.         %ranPhrase = getWord(%phrases,getRandom(0,%count));
  63.         %ranPhrase = strReplace(%ranPhrase,"_"," ");
  64.        
  65.         return %ranPhrase;
  66.     }
  67.     else
  68.         return false;
  69. }
  70.  
  71. //---------------------------------------------------
  72. //This function checks a string sent by another user
  73. //And if it has one of our response triggers
  74. //It\'ll return that word, otherwise it returns false
  75. //---------------------------------------------------
  76.  
  77. function chatBot_messageHasTriggerWord(%string)
  78. {
  79.     %wordCount = getWordCount(%string);
  80.    
  81.     for(%i=0;%i<%wordCount;%i++)
  82.     {
  83.         %word = getWord(%string,%i);
  84.        
  85.         if($chatBot::response[%word] !$= "")
  86.         {
  87.             return %word;
  88.         }
  89.     }
  90.     return false;
  91. }
  92.  
  93. //-------------------------------------------
  94. //This function will attempt to say a string
  95. //As the chat bot, and checks things like
  96. //Flood protection triggering and spamming
  97. //-------------------------------------------
  98.  
  99. function chatBot_say(%string)
  100. {
  101.     %time = getSimTime();
  102.    
  103.     if(%time - $chatBot::lastTalkTime >= $chatBot::timeOut)
  104.     {
  105.         if($chatBot::lastTalkMessage $= %string)
  106.         {
  107.             error("Our chatbot will trigger the flood protection, returning false");
  108.             return false;
  109.         }
  110.         else
  111.         {
  112.             commandToServer(\'messageSent\',$chatBot::name @ " => " @ %string);
  113.             $chatBot::lastTalkMessage = %string;
  114.             $chatBot::lastTalkTime = %time;
  115.         }
  116.        
  117.         return true;
  118.     }
  119.     return false;
  120. }
');