mirror of
				https://github.com/valentineus/iii-module.git
				synced 2025-11-04 04:29:44 +03:00 
			
		
		
		
	RC demo
This commit is contained in:
		@@ -1,12 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
* Function of saving the token in a cookie.
 | 
			
		||||
* When you receive the new value clears all stored cookies.
 | 
			
		||||
* @param $token - The values of the token.
 | 
			
		||||
* The function returns the current ID.
 | 
			
		||||
* Returns zero if no ID is stored.
 | 
			
		||||
*/
 | 
			
		||||
function NewToken($token) {
 | 
			
		||||
  unset($_COOKIE); // Removes all
 | 
			
		||||
  SetCookie("BOT_TOKEN", $token); // Save a new cookie
 | 
			
		||||
function GetID() {
 | 
			
		||||
  // Search current ID...
 | 
			
		||||
  if (isset($_COOKIE['CURRENT_ID'])) {
 | 
			
		||||
    $id = (int)$_COOKIE['CURRENT_ID'] + 1;
 | 
			
		||||
  // ...or returns zero
 | 
			
		||||
  } else {
 | 
			
		||||
    $id = 0;
 | 
			
		||||
  }
 | 
			
		||||
  // We issue results
 | 
			
		||||
  return $id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -33,22 +39,6 @@ function GetSession($token, $bot) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* The function returns the current ID.
 | 
			
		||||
* Returns zero if no ID is stored.
 | 
			
		||||
*/
 | 
			
		||||
function GetID() {
 | 
			
		||||
  // Search current ID...
 | 
			
		||||
  if (isset($_COOKIE['CURRENT_ID'])) {
 | 
			
		||||
    $id = (int)$_COOKIE['CURRENT_ID'] + 1;
 | 
			
		||||
  // ...or returns zero
 | 
			
		||||
  } else {
 | 
			
		||||
    $id = 0;
 | 
			
		||||
  }
 | 
			
		||||
  // We issue results
 | 
			
		||||
  return $id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* The function overrides the current ID to
 | 
			
		||||
* the specified or the next. If any missing ID
 | 
			
		||||
@@ -67,8 +57,29 @@ function SetID($id) {
 | 
			
		||||
    $id = 1;
 | 
			
		||||
  }
 | 
			
		||||
  SetCookie('CURRENT_ID', $id, time()+300); // Save the result
 | 
			
		||||
  // We issue results
 | 
			
		||||
  return $id;
 | 
			
		||||
  return $id; // We issue results
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Cleaning function of the parameter that is passed to it.
 | 
			
		||||
* @param $type - Type cleansed.
 | 
			
		||||
*/
 | 
			
		||||
function ClearingCache($type) {
 | 
			
		||||
  switch ($type) {
 | 
			
		||||
    // Clear the cookies
 | 
			
		||||
    case 'cookies':
 | 
			
		||||
      foreach ($_COOKIE as $key => $value) {
 | 
			
		||||
        SetCookie($key, $value, time()-1000);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    // Clear the POST
 | 
			
		||||
    case 'post':
 | 
			
		||||
      $_POST = array();
 | 
			
		||||
      break;
 | 
			
		||||
    // ...
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
<!-- Beginning footer -->
 | 
			
		||||
<footer class="footer">
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <p class="text-muted">
 | 
			
		||||
      <a href="mailto:dev@valentineus.link">dev@valentineus.link</a>
 | 
			
		||||
    <p class="text-muted text-center">
 | 
			
		||||
        With love <i class="glyphicon glyphicon-heart text-danger"></i> from Russia
 | 
			
		||||
    </p>
 | 
			
		||||
  </div>
 | 
			
		||||
</footer>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,10 @@
 | 
			
		||||
<!-- Start navigation bar -->
 | 
			
		||||
<nav class="navbar navbar-default navbar-fixed-top">
 | 
			
		||||
  <!-- Loaded banner GitHub -->
 | 
			
		||||
  <a href="https://github.com/valentineus/Module-III-API">
 | 
			
		||||
    <img class="github-fork">
 | 
			
		||||
  </a>
 | 
			
		||||
  <!-- Filling panel -->
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <div class="collapse navbar-collapse">
 | 
			
		||||
      <!-- The right side of the navigation bar -->
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
    <div class="col-md-4">
 | 
			
		||||
      <button type="submit" class="btn btn-default">Submit</button>
 | 
			
		||||
      <button type="button" class="btn btn-success" data-toggle="modal" data-target="#SettingsModal">Settings</button>
 | 
			
		||||
      <button type="submit" class="btn btn-danger" name="reset">Reset</button>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div><!-- row -->
 | 
			
		||||
</form>
 | 
			
		||||
@@ -1,8 +1,3 @@
 | 
			
		||||
<?php
 | 
			
		||||
ini_set("display_errors","1");
 | 
			
		||||
ini_set("display_startup_errors","1");
 | 
			
		||||
ini_set('error_reporting', E_ALL);
 | 
			
		||||
?>
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
  <head>
 | 
			
		||||
@@ -20,6 +15,7 @@ ini_set('error_reporting', E_ALL);
 | 
			
		||||
    <!-- Title -->
 | 
			
		||||
    <title>Testing conversational bot</title>
 | 
			
		||||
  </head>
 | 
			
		||||
 | 
			
		||||
  <body>
 | 
			
		||||
    <?php // Connect all of the dependencies
 | 
			
		||||
      include("../src/bot.php"); // Class for working with AI
 | 
			
		||||
@@ -27,16 +23,27 @@ ini_set('error_reporting', E_ALL);
 | 
			
		||||
      include("components/navbar.php"); // Connect the navigation bar
 | 
			
		||||
      include("components/settings.php"); // Connecting a modal window with the settings
 | 
			
		||||
    ?>
 | 
			
		||||
 | 
			
		||||
    <!-- Begin page content -->
 | 
			
		||||
    <div class="container">
 | 
			
		||||
      <div class="page-header">
 | 
			
		||||
        <h1>Communication Panel</h1>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <?php
 | 
			
		||||
        // Treat the reset button
 | 
			
		||||
        if (isset($_POST['reset'])) {
 | 
			
		||||
          ClearingCache("cookies"); // We clear all cookies
 | 
			
		||||
          ClearingCache("post"); // Removes all requests that were not processed
 | 
			
		||||
          header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Checking the token initialization
 | 
			
		||||
        if (isset($_POST['BOT_TOKEN'])) {
 | 
			
		||||
          $token = htmlspecialchars($_POST['BOT_TOKEN']);
 | 
			
		||||
          NewToken($token);
 | 
			
		||||
          ClearingCache("cookies"); // We clear all cookies
 | 
			
		||||
          SetCookie("BOT_TOKEN", $token); // Save a new cookie
 | 
			
		||||
          header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
 | 
			
		||||
        // ...Finding saved token
 | 
			
		||||
        } elseif (isset($_COOKIE['BOT_TOKEN'])) {
 | 
			
		||||
          $token = $_COOKIE['BOT_TOKEN'];
 | 
			
		||||
@@ -47,7 +54,8 @@ ini_set('error_reporting', E_ALL);
 | 
			
		||||
          // Initialize the robot system
 | 
			
		||||
          define('BOT_TOKEN', $token);
 | 
			
		||||
          $bot = new Bot(BOT_TOKEN);
 | 
			
		||||
          $session = GetSession($token, $bot); // Initialize the session
 | 
			
		||||
          // Initialize the session
 | 
			
		||||
          $session = GetSession($token, $bot);
 | 
			
		||||
          if (empty($session)) { // No session? Error! ?>
 | 
			
		||||
            <!-- Error Notification -->
 | 
			
		||||
            <div class="alert alert-danger alert-dismissible" role="alert">
 | 
			
		||||
@@ -65,16 +73,15 @@ ini_set('error_reporting', E_ALL);
 | 
			
		||||
 | 
			
		||||
        // Processes the message
 | 
			
		||||
        if (isset($_POST['textarea'])) {
 | 
			
		||||
          $currentid = GetID(); // Get the current ID
 | 
			
		||||
          $currenttext = htmlspecialchars($_POST['textarea']); // Transform text
 | 
			
		||||
          SavingStories($currentid, $currenttext, 'user'); // Keeping your message
 | 
			
		||||
          $currentid = SetID($currentid); // Get next ID
 | 
			
		||||
          SavingStories($currentid, $bot->say($currenttext), 'bot'); // Save bot response
 | 
			
		||||
          SavingStories(GetID(), $currenttext, 'user'); // Keeping your message
 | 
			
		||||
          $currentid = SetID(GetID()); // Get next ID
 | 
			
		||||
          SavingStories(SetID($currentid), $bot->say($currenttext), 'bot'); // Save bot response
 | 
			
		||||
          header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Connecting the system interface
 | 
			
		||||
        include("components/communication.php"); // Settings panel
 | 
			
		||||
        include("components/on-board-panel.php"); // Settings panel
 | 
			
		||||
        include("components/results.php"); // Output messages
 | 
			
		||||
      ?>
 | 
			
		||||
    </div>
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user