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

botan integration fixes

parent 52e1ef1e
...@@ -34,6 +34,11 @@ class Botan ...@@ -34,6 +34,11 @@ class Botan
*/ */
protected static $token = ''; protected static $token = '';
/**
* @var string The actual command that is going to be reported
*/
public static $command = '';
/** /**
* Initilize botan * Initilize botan
*/ */
...@@ -47,17 +52,30 @@ class 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 $input
* @param string $command * @param string $command
*
* @return bool|string * @return bool|string
* @throws TelegramException
*/ */
public static function track($input, $command = '') public static function track($input, $command = '')
{ {
if (empty(self::$token)) { if (empty(self::$token) || $command != self::$command) {
return false; return false;
} }
...@@ -129,7 +147,9 @@ class Botan ...@@ -129,7 +147,9 @@ class Botan
* *
* @param $url * @param $url
* @param $user_id * @param $user_id
*
* @return string * @return string
* @throws TelegramException
*/ */
public static function shortenUrl($url, $user_id) public static function shortenUrl($url, $user_id)
{ {
......
...@@ -515,11 +515,16 @@ class Telegram ...@@ -515,11 +515,16 @@ class Telegram
//Handle a generic command or non existing one //Handle a generic command or non existing one
$this->last_command_response = $this->executeCommand('Generic'); $this->last_command_response = $this->executeCommand('Generic');
} else { } 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() //execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection //This is to prevent executing a DB query without a valid connection
$this->last_command_response = $command_obj->preExecute(); $this->last_command_response = $command_obj->preExecute();
//Botan.io integration //Botan.io integration, send report after executing the command
if ($this->botan_enabled) { if ($this->botan_enabled) {
Botan::track($this->update, $command); Botan::track($this->update, $command);
} }
...@@ -808,7 +813,6 @@ class Telegram ...@@ -808,7 +813,6 @@ class Telegram
* Enable Botan.io integration * Enable Botan.io integration
* *
* @param $token * @param $token
* @param $custom
* @return Telegram * @return Telegram
*/ */
public function enableBotan($token) 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