コード例 #1
0
function bottalk(&$botmess, $R)
{
    // $botmess is phpMyChat $M
    // Start the session or get the existing session.
    global $U, $T, $myuniqueid, $uid, $numselects, $DbLink;
    // it worked when I simplified the origional bot page not here though.
    $uid = $U;
    #         session_register($U);
    #         session_name($uid) ;
    #         session_id($U) ;                                         // Get the Session name
    $myuniqueid = $U;
    $botresponse = replybotname(stripslashes($botmess), $myuniqueid, C_BOT_NAME);
    // Get bot's response from respond.php
    $BOT = C_BOT_NAME;
    //Format response for phpMyChat DB
    #              $D1 = ereg_replace("[\r]|[\n]|\t", " ",$botresponse->response) ;
    $D1 = preg_replace("/([\r]|[\n]|[\t])/", " ", $botresponse->response);
    $D1 = str_replace("'", "'", $D1);
    $D1 = "<FONT COLOR=" . C_BOT_FONT_COLOR . ">" . $myuniqueid . "> <I>" . $D1 . "</I></FONT>";
    $D1 = trim($D1);
    $DR = addslashes($D1);
    //." NumSelect = ".$numselects;
    // Open and Write it to phpMyChat DB
    $mytime = time() + 2;
    // Add 2 secs to bot time, seperates it in the DB better.
    $DbLink->query("INSERT INTO " . C_MSG_TBL . " VALUES ('{$T}', '{$R}', '{$BOT}', '{$Latin1}', '{$mytime}', '', '{$DR}', '', '')");
}
コード例 #2
0
function bottalk_priv(&$botmess, $R, $UR, $Private, $Read)
{
    // $botmess is phpMyChat $M
    // Start the session or get the existing session.
    global $U, $T, $myuniqueid, $uid, $numselects, $DbLink;
    // it worked when I simplified the origional bot page not here though.
    $uid = $U;
    #         session_register($U);
    #         session_name($uid);
    #         session_id($U) ;                                         // Get the Session name
    $myuniqueid = $U;
    $botresponse = replybotname(stripslashes($botmess), $myuniqueid, C_BOT_NAME);
    // Get bot's response from respond.php
    $BOT = C_BOT_NAME;
    //Format response for phpMyChat DB
    #              $D1 = ereg_replace("[\r]|[\n]|\t", " ",$botresponse->response);
    $D1 = preg_replace("/([\r]|[\n]|[\t])/", " ", $botresponse->response);
    $D1 = str_replace("'", "&#39;", $D1);
    $mytime = time() + 2;
    // Add 2 secs to bot time, seperates it in the DB better.
    #$DbLink = new DB;
    if (C_PRIV_POPUP) {
        $DbLink->query("SELECT allowpopup FROM " . C_REG_TBL . " WHERE username = '******'");
        if ($DbLink->num_rows() != 0) {
            if ($Read == "New" || $Read == "Old") {
                $D1 = "<FONT COLOR=\"" . C_BOT_FONT_COLOR . "\"><I>L_PRIV_PM " . $D1 . "</I></FONT>";
                $DbLink->query("UPDATE " . C_MSG_TBL . " SET pm_read='" . date("Y-m-d H:i:s") . "' WHERE pm_read='New' AND address='" . $BOT . "' AND username='******'");
                $Readu = "New";
            } elseif ($Read == "Neww" || $Read == "Oldw") {
                $D1 = "<FONT COLOR=\"" . C_BOT_FONT_COLOR . "\"><I>L_PRIV_WISP " . $D1 . "</I></FONT>";
                $DbLink->query("UPDATE " . C_MSG_TBL . " SET pm_read='" . date("Y-m-d H:i:s") . "' WHERE pm_read='Neww' AND address='" . $BOT . "' AND username='******'");
                $Readu = "Neww";
            }
        } else {
            if ($Read == "New" || $Read == "Old") {
                $D1 = "<FONT COLOR=\"" . C_BOT_FONT_COLOR . "\"><I>L_PRIV_PM " . $D1 . "</I></FONT>";
                $DbLink->query("UPDATE " . C_MSG_TBL . " SET pm_read='" . date("Y-m-d H:i:s") . "' WHERE pm_read='New' AND address='" . $BOT . "' AND username='******'");
                $Readu = date("Y-m-d H:i:s");
            } elseif ($Read == "Neww" || $Read == "Oldw") {
                $D1 = "<FONT COLOR=\"" . C_BOT_FONT_COLOR . "\"><I>L_PRIV_WISP " . $D1 . "</I></FONT>";
                $DbLink->query("UPDATE " . C_MSG_TBL . " SET pm_read='" . date("Y-m-d H:i:s") . "' WHERE pm_read='Neww' AND address='" . $BOT . "' AND username='******'");
                $Readu = date("Y-m-d H:i:s");
            }
        }
        #		$DbLink->clean_results();
    }
    $D1 = trim($D1);
    $DR = addslashes($D1);
    $DbLink->query("INSERT INTO " . C_MSG_TBL . " VALUES ('{$T}', '{$R}', '{$BOT}', '0', '{$mytime}', '{$U}', '{$DR}', '{$Readu}', '{$UR}')");
}
コード例 #3
0
ファイル: talk.php プロジェクト: aparaschivoiu/webapp
 * @version 0.0.8
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package Interpreter
 * @subpackage Responder
 */
/**
* Include the guts of the program.
*/
include "respond.php";
if (isset($_POST['input'])) {
    $numselects = 0;
    // Start the session or get the existing session.
    session_start();
    $myuniqueid = session_id();
    // Here is where we get the reply.
    $botresponse = replybotname($_POST['input'], $myuniqueid, $_POST['botname']);
    print "<pre>";
    var_dump($botresponse);
    print "</pre>";
    // Print the results.
    print "<B>RESPONSE: " . $botresponse->response . "<BR></b>";
    print "<BR><BR>execution time: " . $botresponse->timer;
    print "<BR>numselects= {$numselects}";
    //var_dump($botresponse);
    //var_dump($botresponse);
    //print_r($botresponse->inputs);
    //print_r($botresponse->patternsmatched);
    // Include a form so they can say more. Note the hidden part for people that do not have trans sid on but want non-cookie users to be able to use the system.
    ?>

	<html>
コード例 #4
0
ファイル: newuser.php プロジェクト: aparaschivoiu/webapp
            } else {
                $user['id'] = mysql_insert_id();
                $r['user'] = $user;
            }
        }
    } else {
        $in = "INSERT INTO users (identifier, photoURL, displayName, firstName, gender, birthday, email, region, provider)\n                VALUES('" . $user['identifier'] . "','" . $user['photoURL'] . "','" . $user['displayName'] . "','" . $user['firstName'] . "','" . $user['gender'] . "',\n                    '','" . $user['email'] . "','" . $user['region'] . "', '{$provider}')";
        $rr = mysql_query($in);
        if (mysql_errno()) {
            $r['error'] = mysql_error();
        } else {
            $user['id'] = mysql_insert_id();
            $r['user'] = $user;
        }
    }
    if (!isset($r['error'])) {
        if ($user['firstName'] != "") {
            $name = $user['firstName'];
        } else {
            $name = $user['displayName'];
            $name = explode(" ", $name);
            $name = $name[0];
        }
        error_log("New user, greetings: NOMBRE " . $name);
        $botresponse = replybotname("NOMBRE " . $name, $user['id'], 'Polo');
        $r['body'] = trim(preg_replace('/\\s+/', ' ', $botresponse->response));
    }
} else {
    $r['error'] = "User invalid";
}
echo json_encode($r);
コード例 #5
0
ファイル: octavius.php プロジェクト: erico-deh/ocPortal
 /**
  * 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;
 }
コード例 #6
0
ファイル: talk.php プロジェクト: aparaschivoiu/webapp
<?php

header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Date in the past
include "programe/respond.php";
$r = array();
if (isset($_POST['input']) && !empty($_POST['input']) && isset($_POST['user']) && !empty($_POST['user'])) {
    $botresponse = replybotname($_POST['input'], $_POST['user'], 'Polo');
    $r = parseout(trim(preg_replace('/\\s+/', ' ', $botresponse->response)));
    echo $r;
}