Nobot

Help and bugs.

Re: Nobot

Postby Fex » December 30th, 2011, 2:32 pm

I uploaded your modified code as
bot/debugging.php
but I can figure out how to execute that, either. :(
Fex
Casual Member
 
Posts: 16
Joined: December 28th, 2011, 1:57 am

Re: Nobot

Postby GeekCaveCreations » December 30th, 2011, 6:16 pm

Actually, that code was meant to replace just the function within the file, not the entire file. Oops? Hang on a sec, and I'll post the entire, modified file. And other than changing the settings from within the file, there's nothing else that you need to do. It's all built in. Just chat with your bot as normal, and then either watch the screen, or look at the generated file.

{time passes}

Code: Select all
<?php
//-----------------------------------------------------------------------------------------------
//Program-o Version 1.0.4
//PHP MYSQL AIML interpreter
//Written by Elizabeth Perreau
//Feb 2010
//for more information and support please visit www.program-o.com
//-----------------------------------------------------------------------------------------------
//debugging.php
//contains simple functions for debugging the bot
//-----------------------------------------------------------------------------------------------
//error handler to get the errors emailed to you for debugging
//set_error_handler("myHandler"); //comment this out if you do not want to be emailed error messages your bot makes...
error_reporting(0); //uncomment this if you want to hide all errors your bot code may make from the user
//error_reporting(E_ALL); //uncomment this if you want to show all errors to the user

//debuglevels
$debugMode = 0; // special turn on and off to test this and that
//$debugMode = 0; // show nothing
//$debugMode = 1; // show everything...
//$debugMode = 2; // show sql errors
//$debugMode = 3; // show gerenal debug info
//$debugMode = 4; // show naviagation only... for tracing which tag the program is examining
//$debugMode = 5; // show everything and show the array at this point

//alter this for your location needed for debuging only if running two versions live/dev
$location = "live";
//if you wish the program to email you you errors instead of displaying them set the flag below to 1 if not then set to 0
$mailerrors = 0;
//if you have chosen to report errors to your email address set the address here
$debugemail = "youremail@yourdomain.com";
//to report on long scripts set the seconds here and any script that take longer than nSeconds will be emailed if mailerrors (flag=1)
$longScriptSeconds = 7;

// If you wish to save the debug output to a text file, then alter the following:
define("SAVE_TO_FILE", true); // set to false to remove file logging.
define("DEBUG_FILE", "txt/runDebug.txt"); // set this to your preferred directory/file name.

//-----------------------------------------------------------------------------------------------
//DO NOT EDIT BELOW THIS LINE
//-----------------------------------------------------------------------------------------------
//debugMessage()
//Just indicate which debug level we are in ... if any
//-----------------------------------------------------------------------------------------------
function debugMessage()
{
   global $debugMode;
   if($debugMode!=0) //0 = hide all debugging
   {
      echo "<h4>Debug Level: $debugMode</h4>";
      switch ($debugMode)
      {
         case 1:
            echo "Show All";
            break;
         default:
            echo "Show Special";
            break;
      }
      echo "<hr>";
   }
   
}

//-------------------------------------------------------------------------
//runDebug($level, $fileName, $functionName, $line, $info)
//function to display information depending on the debug level
//-------------------------------------------------------------------------
function runDebug($level, $fileName, $functionName, $line, $info) {
  global $debugMode;
  // set precise time
  list($us, $ts) = split(" ", microtime());
  $us = round($us, 4);
  $s = (int)date("s") + (float)$us;
  $s = ($s < 10) ? '0'.$s : $s;
  $debug = "";
  $fileSave = "FUNCTION: $functionName in file $fileName at line $line ";
  $fileSave .= $info;
  $fileSave .= "\r\n".date("H:i:").$s;
  $fileSave .= "\r\n";

  if($debugMode == 0) { //show nothing
  }
  elseif($debugMode == 1) {//show everything
    $debug .= "<hr><br><br><b>FUNCTION: $functionName in file $fileName at line $line</b>";
    $debug .= $info;
    $debug .= "<br>".date("H:i:").$s;
    $debug .= "<hr>";
  }
  elseif(($debugMode == $level)&&($level==5)) { //show only if we have set this to equal...
    $debug .= "<b>FUNCTION: $functionName in file $fileName at line $line</b>";
    $debug .= $info;
    $debug .= "<br>".date("H:i:").$s;
    $debug .= displayArray();
    $debug .= "<hr>";
  }
  elseif($debugMode == $level) {//show only if we have set this to equal...
    $debug .= "<b>FUNCTION: $functionName in file $fileName at line $line</b>";
    $debug .= $info;
    $debug .= "<br>".date("H:i:").$s;
    $debug .= "<hr>";
  }
  if (SAVE_TO_FILE) { // save debug output to a file only if set in the preferences, above.
    // We need to take out HTML formatting for the debug file, and replace with correct strings
    $fileSave = str_replace("<br><br>", "", $fileSave); // Remove unnecessary "line breaks"
    $fileSave = str_replace("<br>", "\n", $fileSave); // change HTML line breaks to text versions
    $fileSave = str_replace("<table border=1>", "", $fileSave);
    $fileSave = str_replace("</table>", "", $fileSave);
    $fileSave = str_replace("<tr>", "| ", $fileSave);
    $fileSave = str_replace("</tr>", "\n", $fileSave);
    $fileSave = str_replace("<td>", "", $fileSave);
    $fileSave = str_replace("</td>", " | ", $fileSave);
    $fileSave = str_replace("<hr>", "", $fileSave);
    $fileSave = str_replace("<pre>", "", $fileSave);
    $fileSave = str_replace("</pre>", "", $fileSave);
    $fileSave = str_replace("&nbsp;", " ", $fileSave);
    $fileSave = str_replace("\n", "\r\n", $fileSave);   // Notepad hack. Not necessary for non-windows systems, or if Notepad isn't used.
    $fileSave = htmlspecialchars_decode($fileSave);

    // PHP 5+ code - For < PHP 5, a different method is needed.
    $x = file_put_contents(DEBUG_FILE, $fileSave."\r\n\r\n", FILE_APPEND); //
  }
    echo $debug;
}
//-----------------------------------------------------------------------------------------------
//displayArray($response_Array)
//Sometime when debugging we want to show the response_array parts....
//this will only be triggered if the debug level is 5
//-----------------------------------------------------------------------------------------------
function displayArray($response_Array)
{
   //these are the parts we want to show..... add more if you want to show more array parts from the response array
   $viewList=array('responseparts','rname','lookingfor','answer','anagramanswer','htmltemplate','topic');
   if($response_Array!="")
   {
      echo "<pre>"; //format
      foreach($viewList as $u => $item) //loop
      {
         if(isset($response_Array[$item])) //if she
         {
            echo "<br>$item=<br>"; //show
            print_r($response_Array[$item]);
         }
      }
      echo "<pre>";
   }
   else
   {
      echo "<br>array not set";
   }
}

function emailthis($response_Array,$subject)
{
   global $debugemail,$mailerrors;
   
   if($mailerrors==1)
   {
      if(is_array($response_Array))
      {
         $body = "";
         foreach($response_Array as $item => $r)
         {
            if(is_array($r))
            {
               $body .= "\n\t[$item]";
            
                  foreach($r as $i => $t)
                  {
                     $body .= "\n\t\t[$i] = $t";
                  }
            }
            else
            {
               $body .= "\n\t[$item] = $r";
            }
         }
         $body .= "";   
      }
      else
      {
         $body = $response_Array;
      }   
         $to      = $debugemail;
         
         $headers = 'From: '.$debugemail . "\r\n" .
            'Reply-To: '.$debugemail . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
         
      mail($to, $subject, $body, $headers);
   }
}

function endTime($response_Array,$time_start)
{
   global $location,$mailerrors,$longScriptSeconds;
   
   if($mailerrors==1)
   {
   
      $time_end = microtime(true);
      $time = $time_end - $time_start;
      
      if($time>$longScriptSeconds)
      {
         emailthis($response_Array,"$location - Long Script = $time seconds");
      }
   }
}

function myHandler($code, $msg, $file, $line, $context)
{
    // print error page
   global $location,$debugemail;
    // email error to admin
    $body = "$msg at $file ($line), timed at " . date ("d-M-Y h:i:s", mktime());
    $body .= "\n\n<pre>" . print_r($context, TRUE) ."</pre>";
    // log error to file, with context
    $logData = date("d-M-Y h:i:s", mktime()) . ", $code, $msg, $line, $file\n";
    //file_put_contents("web.log", $logData, FILE_APPEND);

      $subject = "$location - $msg at $file ($line)";
   $to      = $debugemail;
      
      $headers = 'From: '.$debugemail . "\r\n" .
         'Reply-To: '.$debugemail . "\r\n" .
         'X-Mailer: PHP/' . phpversion();
      
   mail($to, $subject, $body, $headers);
}

?>


Copy the code here and paste it into a text editor, make the necessary changes to the settings (such as email address, debug level and whether or not to save the debug data as a file), then save the file as debugging.php and upload it into your server in the bot directory. then give your bot a try. :)

NOTE - If you use the default setting for the location/name of the debug file, then you need to create a folder within the bot directory, named "txt". If you don't, you'll get errors.
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Previous

Return to Bugs and Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron