示例#1
0
$templatesinserted = 0;
$patternsinserted = 0;
$depth = array();
$whaton = "";
$pattern = "";
$topic = "";
$that = "";
$template = "";
$startupwhich = "";
$splitterarray = array();
$inputarray = array();
$genderarray = array();
$personarray = array();
$person2array = array();
loadstartup();
makesubscode();
print "<font size='3' color='RED'><b>DONE LOADING</B><br /></font>\n";
print "<font size='3' color='BLUE'>Inserted {$templatesinserted} categories into database</font><br />\n";
print "<font size='3' color='BLUE'>Inserted {$patternsinserted} sentences into database</font><br /><br />\n";
print "<font size='3' color='RED'><b>WARNING!</b> You should either delete or rename the botloader.php and botloaderinc.php scripts, otherwise people may be able to abuse your server.</b></font>\n";
print "<p><font size='3' color='BLACK'><a href='talk.php'>Click here to talk to the bot</a></p></font>\n";
print "<br />";
ss_timing_stop("all");
print "<br /><br /><font size='3' color='BLACK'>execution time: " . ss_timing_current("all");
$avgts = round($templatesinserted / ss_timing_current("all"));
$avgtm = round($templatesinserted / (ss_timing_current("all") / 60));
print "<br /><font size='3' color='BLACK'>Templates per second={$avgts}<br />";
print "<font size='3' color='BLACK'>Templates per minute={$avgtm}<br />";
$avgps = round($patternsinserted / ss_timing_current("all"));
$avgpm = round($patternsinserted / (ss_timing_current("all") / 60));
print "<font size='3' color='BLACK'>Patterns per second={$avgps}<br />";
示例#2
0
 /**
  * Handle hooks supported bot commands. Note multiple bots may support the same commands, and all respond. It is recommended all bots support the command 'help'.
  *
  * @param  AUTO_LINK		The ID of the chat room
  * @param  string			The command used. This is just the chat message, so you can encode and recognise your own parameter scheme if you like.
  * @return ?string		Bot reply (NULL: bot does not handle the command)
  */
 function handle_commands($room_id, $string)
 {
     require_code('developer_tools');
     destrictify();
     if ($string == '((SHAKE))') {
         return NULL;
     }
     if (file_exists(get_custom_file_base() . '/sources_custom/programe')) {
         if (get_value('octavius_installed') !== '1') {
             disable_php_memory_limit();
             if (function_exists('set_time_limit')) {
                 @set_time_limit(600);
             }
             $GLOBALS['SITE_DB']->query("DROP TABLE bot", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE bots", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE conversationlog", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE dstore", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE gmcache", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE gossip", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE patterns", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE templates", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE thatindex", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("DROP TABLE thatstack", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE bot (\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  bot tinyint(4) NOT NULL default '0',\n\t\t\t\t  name varchar(255) NOT NULL default '',\n\t\t\t\t  value text NOT NULL,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY botname (bot,name)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE bots (\n\t\t\t\t  id tinyint(3) unsigned NOT NULL auto_increment,\n\t\t\t\t  botname varchar(255) NOT NULL default '',\n\t\t\t\t  PRIMARY KEY  (botname),\n\t\t\t\t  KEY id (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE conversationlog (\n\t\t\t\t  bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  input text,\n\t\t\t\t  response text,\n\t\t\t\t  uid varchar(255) default NULL,\n\t\t\t\t  enteredtime timestamp(14) NOT NULL,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE dstore (\n\t\t\t\t  uid varchar(255) default NULL,\n\t\t\t\t  name text,\n\t\t\t\t  value text,\n\t\t\t\t  enteredtime timestamp(14) NOT NULL,\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY nameidx (name(40))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE gmcache (\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t  template int(11) NOT NULL default '0',\n\t\t\t\t  inputstarvals text,\n\t\t\t\t  thatstarvals text,\n\t\t\t\t  topicstarvals text,\n\t\t\t\t  patternmatched text,\n\t\t\t\t  inputmatched text,\n\t\t\t\t  combined text NOT NULL,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY combined (bot,combined(255))\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE gossip (\n\t\t\t\t  bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t  gossip text,\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY botidx (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE patterns (\n\t\t\t\t  bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  word varchar(255) default NULL,\n\t\t\t\t  ordera tinyint(4) NOT NULL default '0',\n\t\t\t\t  parent int(11) NOT NULL default '0',\n\t\t\t\t  isend tinyint(4) NOT NULL default '0',\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY wordparent (parent,word),\n\t\t\t\t  KEY botid (bot)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE templates (\n\t\t\t\t  bot tinyint(3) unsigned NOT NULL default '0',\n\t\t\t\t  id int(11) NOT NULL default '0',\n\t\t\t\t  template text NOT NULL,\n\t\t\t\t  pattern varchar(255) default NULL,\n\t\t\t\t  that varchar(255) default NULL,\n\t\t\t\t  topic varchar(255) default NULL,\n\t\t\t\t  PRIMARY KEY  (id),\n\t\t\t\t  KEY bot (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE thatindex (\n\t\t\t\t  uid varchar(255) default NULL,\n\t\t\t\t  enteredtime timestamp(14) NOT NULL,\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  PRIMARY KEY  (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $GLOBALS['SITE_DB']->query("CREATE TABLE thatstack (\n\t\t\t\t  thatid int(11) NOT NULL default '0',\n\t\t\t\t  id int(11) NOT NULL auto_increment,\n\t\t\t\t  value varchar(255) default NULL,\n\t\t\t\t  enteredtime timestamp(14) NOT NULL,\n\t\t\t\t  PRIMARY KEY  (id)\n\t\t\t\t) TYPE=MyISAM", NULL, NULL, true);
             $fp = "";
             $templatesinserted = 0;
             $depth = array();
             $whaton = "";
             $pattern = "";
             $topic = "";
             $that = "";
             $template = "";
             $startupwhich = "";
             $splitterarray = array();
             $inputarray = array();
             $genderarray = array();
             $personarray = array();
             $person2array = array();
             require_code('programe/botloaderfuncs');
             loadstartup();
             makesubscode();
             set_value('octavius_installed', '1');
         }
         require_code('programe/respond');
         $response = replybotname(str_replace('?', '.', $string), get_session_id(), 'octavius');
         restrictify();
         if (is_null($response) || $response->response == '') {
             return NULL;
         }
         return '[html]' . $response->response . '[/html]';
     }
     // Eliza...
     // setup initial variables and values
     $kwarray = array();
     $vararray = array();
     $resparray = array();
     $priarray = array();
     $wordarray = array();
     $kwcount = 0;
     $varcount = 0;
     $respcount = 0;
     $syncount = 0;
     mt_srand((double) microtime() * 1000000);
     // load knowledge file
     $lines_array = file(get_custom_file_base() . "/sources_custom/hooks/modules/chat_bots/knowledge.txt");
     $count = count($lines_array);
     // This for loop goes through the entire knowledge file and places
     // the elements into arrays.  This later allows us to pull the information
     // (ie. key words, variances on the keywords, and responses) out of the
     // arrays.
     for ($x = 0; $x < $count; $x++) {
         $lines_array[$x] = trim($lines_array[$x]);
         $lines_array[$x] = ereg_replace("[\\]", "", $lines_array[$x]);
         if (strstr($lines_array[$x], "key:")) {
             eregi("key: (.*)", $lines_array[$x], $kw);
             $kwarray[$kwcount] = strtoupper($kw[1]);
             $currentkw = $kwcount;
             $kwcount++;
             $varcount = 0;
             // reset varcount to null
             $respcount = 0;
             // reset respcount to null
             $pricount = 0;
             // reset pricount to null
         } else {
             if (strstr($lines_array[$x], "var:")) {
                 eregi("var: (.*)", $lines_array[$x], $variance);
                 $vararray[$currentkw][$varcount] = strtoupper($variance[1]);
                 $varcurrent = $varcount;
                 $varcount++;
                 $respcount = 0;
             } else {
                 if (strstr($lines_array[$x], "pri:")) {
                     eregi("pri: (.*)", $lines_array[$x], $priority);
                     $priarray[$currentkw] = $priority[1];
                 } else {
                     if (strstr($lines_array[$x], "resp:")) {
                         eregi("resp: (.*)", $lines_array[$x], $response);
                         $resparray[$currentkw][$varcurrent][$respcount] = $response[1];
                         $respcount++;
                     } else {
                         if (strstr($lines_array[$x], "syn:")) {
                             eregi("syn: (.*)", $lines_array[$x], $synonym);
                             $synonymarray[$syncount] = strtoupper($synonym[1]);
                             $syncount++;
                         } else {
                             if (strstr($lines_array[$x], "goto:")) {
                                 eregi("goto: (.*)", $lines_array[$x], $goto);
                                 $goto = strtoupper($goto[1]);
                                 // find the keyword
                                 for ($zcount = 0; $zcount < count($kwarray); $zcount++) {
                                     // if the keyword already exists
                                     if (eregi($goto, $kwarray[$zcount])) {
                                         // then we assign properties of the keyword
                                         $vararray[$currentkw][0] = $kwarray[$currentkw];
                                         $resparray[$currentkw] = $resparray[$zcount];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $y = 0;
     $z = 0;
     $v = 0;
     $bestpriority = -2;
     $originalstring = $string;
     if (!$string) {
         $string = "hello";
     }
     $string = strtoupper($string);
     // Figures out what word in the string has the most priority.
     // It can then check words to the left/right of this word depending
     // upon settings in the knowledge.txt file.
     while ($y < count($kwarray)) {
         // remove beginning and trailing white space, breaks, etc
         $string = trim($string);
         // remove puncuation from string
         $string = ereg_replace('[!?,.]', '', $string);
         // split the string up into seperate words
         $wordarray = explode(" ", $string);
         while ($v < count($wordarray)) {
             if (eregi($wordarray[$v] . "\$", $kwarray[$y])) {
                 // find which word holds the most weight in the sentance
                 if ($bestpriority == -2) {
                     $bestpriority = $y;
                 } else {
                     if ($priarray[$bestpriority] < $priarray[$y]) {
                         $bestpriority = $y;
                     }
                 }
             }
             $v++;
         }
         $v = 0;
         $y++;
     }
     // find the variance with the most matching words
     $vcount = 0;
     while ($vcount < count($vararray[$bestpriority])) {
         if (strstr($vararray[$bestpriority][$vcount], "@")) {
             eregi("@(.*)", $vararray[$bestpriority][$vcount], $syn);
             // fix this
             $syn = $syn[1];
             for ($x = 0; $x < count($synonymarray); $x++) {
                 if (eregi($syn, strtoupper($synonymarray[$x]))) {
                     $sarray = explode(" ", $synonymarray[$x]);
                     for ($f = 0; $f < count($sarray); $f++) {
                         $newstring = ereg_replace("@(.*)\$", $sarray[$f], $vararray[$bestpriority][$vcount]);
                         // works to this point
                         if (eregi($newstring . "\$", $string)) {
                             $varray = explode(" ", $vararray[$bestpriority][$vcount]);
                             if (count($varray) > $pvarray) {
                                 $bestvariance = $vcount;
                                 $pvarray = count($varray);
                             }
                         }
                     }
                 }
             }
         } else {
             if (ereg($vararray[$bestpriority][$vcount], $string)) {
                 $varray = explode(" ", $vararray[$bestpriority][$vcount]);
                 if (count($varray) > $pvarray) {
                     $bestvariance = $vcount;
                     $pvarray = count($varray);
                 }
             }
         }
         $vcount++;
     }
     // Using the bestpriority (aka the keyword (key:) with the most weight in the sentence)
     // and the bestvariance (aka, the variance (var:) phrase that most fits the context of
     // the original sentence, we form a response.
     if (count($resparray[$bestpriority][$bestvariance]) > 1) {
         $random = mt_rand(0, count($resparray[$bestpriority][$bestvariance]) - 1);
     } else {
         $random = 0;
     }
     $response = $resparray[$bestpriority][$bestvariance][$random];
     if ($response == "") {
         $response = "Sorry, I don't understand what you're trying to say.";
     }
     $originalstring = ereg_replace("[\\]", "", $originalstring);
     restrictify();
     return $response;
 }