Commit 0cd6a07b authored by Jack'lul's avatar Jack'lul

botan integration fixes

parent 52e1ef1e
......@@ -34,6 +34,11 @@ class Botan
*/
protected static $token = '';
/**
* @var string The actual command that is going to be reported
*/
public static $command = '';
/**
* Initilize botan
*/
......@@ -47,17 +52,30 @@ class Botan
}
/**
* Track function
* Lock function to make sure only the first command is reported
* ( in case commands are calling other commands $telegram->executedCommand() )
*
* @todo Advanced integration: https://github.com/botanio/sdk#advanced-integration
* @param string $command
*/
public static function lock($command = '')
{
if (empty(self::$command)) {
self::$command = $command;
}
}
/**
* Track function
*
* @param string $input
* @param string $command
*
* @return bool|string
* @throws TelegramException
*/
public static function track($input, $command = '')
{
if (empty(self::$token)) {
if (empty(self::$token) || $command != self::$command) {
return false;
}
......@@ -129,7 +147,9 @@ class Botan
*
* @param $url
* @param $user_id
*
* @return string
* @throws TelegramException
*/
public static function shortenUrl($url, $user_id)
{
......
......@@ -515,11 +515,16 @@ class Telegram
//Handle a generic command or non existing one
$this->last_command_response = $this->executeCommand('Generic');
} else {
//Botan.io integration, make sure only the command user executed is reported
if ($this->botan_enabled) {
Botan::lock($command);
}
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
$this->last_command_response = $command_obj->preExecute();
//Botan.io integration
//Botan.io integration, send report after executing the command
if ($this->botan_enabled) {
Botan::track($this->update, $command);
}
......@@ -808,7 +813,6 @@ class Telegram
* Enable Botan.io integration
*
* @param $token
* @param $custom
* @return Telegram
*/
public function enableBotan($token)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment