0
mirror of https://github.com/valentineus/iii-module.git synced 2025-07-01 11:00:27 +03:00

Final touches

This commit is contained in:
Valentin Popov
2016-09-21 18:38:59 +04:00
parent 07c1b99cb5
commit f44d37a204
3 changed files with 20 additions and 18 deletions

View File

@ -2,6 +2,7 @@
/** /**
* The function returns the current ID. * The function returns the current ID.
* Returns zero if no ID is stored. * Returns zero if no ID is stored.
* @return integer - ID session.
*/ */
function GetID() { function GetID() {
// Search current ID... // Search current ID...
@ -21,6 +22,7 @@ function GetID() {
* init or returns zero on failure. * init or returns zero on failure.
* @param $token - The values of the token. * @param $token - The values of the token.
* @param $bot - Initialized bot. * @param $bot - Initialized bot.
* @return string - ID bot session.
*/ */
function GetSession($token, $bot) { function GetSession($token, $bot) {
// Search the old session // Search the old session
@ -44,6 +46,7 @@ function GetSession($token, $bot) {
* the specified or the next. If any missing ID * the specified or the next. If any missing ID
* returns the one. * returns the one.
* @param $id - Current ID. * @param $id - Current ID.
* @return integer - Next ID.
*/ */
function SetID($id) { function SetID($id) {
// Process the specified ID... // Process the specified ID...

View File

@ -19,7 +19,7 @@
<body> <body>
<?php // Connect all of the dependencies <?php // Connect all of the dependencies
include("../src/bot.php"); // Class for working with AI include("../src/bot.php"); // Class for working with AI
include("components/class-application.php"); // Class to work with application logic include("components/functions.php"); // Class to work with application logic
include("components/navbar.php"); // Connect the navigation bar include("components/navbar.php"); // Connect the navigation bar
include("components/settings.php"); // Connecting a modal window with the settings include("components/settings.php"); // Connecting a modal window with the settings
?> ?>

View File

@ -5,15 +5,16 @@
private $salt = 'some very-very long string without any non-latin characters due to different string representations inside of variable programming languages'; private $salt = 'some very-very long string without any non-latin characters due to different string representations inside of variable programming languages';
/** /**
* @param $key - Ключ из урла после создания инфа * @param $key - The session key of the row address.
*/ */
public function __construct($key) { public function __construct($key) {
$this->key = $key; $this->key = $key;
} }
/** /**
* @param null $session - Идентификатор сессии существующей, если нет то создается новая * The function of creating the session.
* @return string Идентификатор текущей сессии * @param $session - Session ID.
* @return string - The ID of the current session.
*/ */
public function session($session = null) { public function session($session = null) {
if ($session === null) { if ($session === null) {
@ -22,14 +23,14 @@
} else { } else {
$this->session = $session; $this->session = $session;
} }
// We issue results
return $this->session; return $this->session;
} }
/** /**
* ОТправить сообщение боту * Function send a message to the bot.
* @param string $message Сообщение * @param $message - Message text.
* @return string Ответ * @return string - Returns a response from a bot.
*/ */
public function say($message) { public function say($message) {
$request = '["'.$this->session.'","'.$message.'"]'; $request = '["'.$this->session.'","'.$message.'"]';
@ -42,41 +43,39 @@
)); ));
$response = curl_exec($myCurl); $response = curl_exec($myCurl);
curl_close($myCurl); curl_close($myCurl);
// We issue results
return $this->decode($response)->result->text->tts; return $this->decode($response)->result->text->tts;
} }
/** /**
* Кодирование сообщения * Encode message before sending it.
* @param $message * @param $message - The response from the bot.
* @return string * @return string - A coded message.
*/ */
private function encode($message) { private function encode($message) {
$message = base64_encode($message); $message = base64_encode($message);
$ml = strlen($message); $ml = strlen($message);
$kl = strlen($this->salt); $kl = strlen($this->salt);
$encoded = "";
for ($i = 0; $i < $ml; $i++) { for ($i = 0; $i < $ml; $i++) {
$encoded = $encoded . ($message[$i] ^ $this->salt[$i % $kl]); $encoded = $encoded . ($message[$i] ^ $this->salt[$i % $kl]);
} }
// We issue results
return base64_encode($encoded); return base64_encode($encoded);
} }
/** /**
* Декодирование сообщения * The function of decoding the received message.
* @param $message * @param $message - The response from the bot.
* @return mixed|null * @return mixed|null
*/ */
private function decode($message) { private function decode($message) {
$msg = base64_decode($message); $msg = base64_decode($message);
$ml = strlen($msg); $ml = strlen($msg);
$kl = strlen($this->salt); $kl = strlen($this->salt);
$decoded = "";
for ($i = 0; $i < $ml; $i++) { for ($i = 0; $i < $ml; $i++) {
$decoded.= ($msg[$i] ^ $this->salt[$i % $kl]); $decoded.= ($msg[$i] ^ $this->salt[$i % $kl]);
} }
// We issue results
return json_decode(base64_decode($decoded)); return json_decode(base64_decode($decoded));
} }
} }