{"action":"created","comment":{"url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/comments/93889694","pull_request_review_id":14420429,"id":93889694,"diff_hunk":"@@ -20,82 +23,107 @@\n class Botan\n {\n     /**\n-     * @var string Tracker request url\n+     * Botan.io API URL\n+     *\n+     * @var string\n      */\n-    protected static $track_url = 'https://api.botan.io/track?token=#TOKEN&uid=#UID&name=#NAME';\n+    protected static $api_base_uri = 'https://api.botan.io';\n \n     /**\n-     * @var string Url Shortener request url\n+     * Yandex AppMetrica application key\n+     *\n+     * @var string\n      */\n-    protected static $shortener_url = 'https://api.botan.io/s/?token=#TOKEN&user_ids=#UID&url=#URL';\n+    protected static $token = '';\n \n     /**\n-     * @var string Yandex AppMetrica application key\n+     * Guzzle Client object\n+     *\n+     * @var \\GuzzleHttp\\Client\n      */\n-    protected static $token = '';\n+    private static $client;\n \n     /**\n-     * @var string The actual command that is going to be reported\n+     * The actual command that is going to be reported\n+     *\n+     *  Set as public to let the developers either:\n+     *  - block tracking from inside commands by setting the value to non-existent command\n+     *  - override which command is tracked when commands call other commands with executedCommand()\n+     *\n+     * @var string\n      */\n     public static $command = '';\n \n     /**\n      * Initialize Botan\n      *\n-     * @param $token\n+     * @param  string $token\n+     * @param  integer $timeout\n+     *\n      * @throws \\Longman\\TelegramBot\\Exception\\TelegramException\n      */\n-    public static function initializeBotan($token)\n+    public static function initializeBotan($token, $timeout = 3)\n     {\n-        if (empty($token) || !is_string($token)) {\n-            throw new TelegramException('Botan token should be a string!');\n+        if (empty($token)) {\n+            throw new TelegramException('Botan token is empty!');\n         }\n-        self::$token = $token;\n+\n+        if (!is_numeric($timeout)) {\n+            throw new TelegramException('Timeout must be a number!');\n+        }\n+\n+        self::$token   = $token;\n+        self::$client  = new Client(['base_uri' => self::$api_base_uri, 'timeout' => $timeout]);\n+\n         BotanDB::initializeBotanDb();\n     }\n \n     /**\n-     * Lock function to make sure only the first command is reported\n-     * ( in case commands are calling other commands $telegram->executedCommand() )\n+     * Lock function to make sure only the first command is reported (the one user requested)\n      *\n-     * @param  string $command\n+     *  This is in case commands are calling other commands with executedCommand()\n+     *\n+     * @param string $command\n      */\n     public static function lock($command = '')\n     {\n         if (empty(self::$command)) {\n-            self::$command = $command;\n+            self::$command = strtolower($command);\n         }\n     }\n \n     /**\n      * Track function\n      *\n-     * @param  string $input\n+     * @param  \\Longman\\TelegramBot\\Entities\\Update $update\n      * @param  string $command\n      *\n      * @return bool|string\n      * @throws \\Longman\\TelegramBot\\Exception\\TelegramException\n      */\n-    public static function track($input, $command = '')\n+    public static function track(Update $update, $command = '')\n     {\n-        if (empty(self::$token) || $command !== self::$command) {\n+        if (empty(self::$token) || strtolower($command) !== self::$command) {\n             return false;\n         }\n \n-        if (empty($input)) {\n-            throw new TelegramException('Input is empty!');\n+        if (empty($update)) {\n+            throw new TelegramException('Update object is empty!');\n         }\n \n+        // Release the lock in case someone runs getUpdates in foreach loop\n         self::$command = '';\n \n-        $obj  = json_decode($input, true);\n+        // For now, this is the only way\n+        $update_data = (array) $update;\n+\n         $data = [];\n-        if (isset($obj['message'])) {\n-            $data       = $obj['message'];\n+        if ($update->getMessage()) {","path":"src/Botan.php","position":133,"original_position":133,"commit_id":"987dbf9c139734475a676ebc0f25192f8142d736","original_commit_id":"987dbf9c139734475a676ebc0f25192f8142d736","user":{"login":"noplanman","id":9423417,"avatar_url":"https://avatars.githubusercontent.com/u/9423417?v=3","gravatar_id":"","url":"https://api.github.com/users/noplanman","html_url":"https://github.com/noplanman","followers_url":"https://api.github.com/users/noplanman/followers","following_url":"https://api.github.com/users/noplanman/following{/other_user}","gists_url":"https://api.github.com/users/noplanman/gists{/gist_id}","starred_url":"https://api.github.com/users/noplanman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noplanman/subscriptions","organizations_url":"https://api.github.com/users/noplanman/orgs","repos_url":"https://api.github.com/users/noplanman/repos","events_url":"https://api.github.com/users/noplanman/events{/privacy}","received_events_url":"https://api.github.com/users/noplanman/received_events","type":"User","site_admin":false},"body":"Would be nice if we could find a way to shorten this epic `if else` block and make it more dynamic.\r\nNot priority though, more a though since you've touched code here 😃 ","created_at":"2016-12-27T01:46:19Z","updated_at":"2016-12-27T01:54:57Z","html_url":"https://github.com/akalongman/php-telegram-bot/pull/365#discussion_r93889694","pull_request_url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365","_links":{"self":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/comments/93889694"},"html":{"href":"https://github.com/akalongman/php-telegram-bot/pull/365#discussion_r93889694"},"pull_request":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365"}}},"pull_request":{"url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365","id":99374515,"html_url":"https://github.com/akalongman/php-telegram-bot/pull/365","diff_url":"https://github.com/akalongman/php-telegram-bot/pull/365.diff","patch_url":"https://github.com/akalongman/php-telegram-bot/pull/365.patch","issue_url":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/365","number":365,"state":"open","locked":false,"title":"Botan improvements and misc fixes","user":{"login":"jacklul","id":8418678,"avatar_url":"https://avatars.githubusercontent.com/u/8418678?v=3","gravatar_id":"","url":"https://api.github.com/users/jacklul","html_url":"https://github.com/jacklul","followers_url":"https://api.github.com/users/jacklul/followers","following_url":"https://api.github.com/users/jacklul/following{/other_user}","gists_url":"https://api.github.com/users/jacklul/gists{/gist_id}","starred_url":"https://api.github.com/users/jacklul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacklul/subscriptions","organizations_url":"https://api.github.com/users/jacklul/orgs","repos_url":"https://api.github.com/users/jacklul/repos","events_url":"https://api.github.com/users/jacklul/events{/privacy}","received_events_url":"https://api.github.com/users/jacklul/received_events","type":"User","site_admin":false},"body":"Botan.io:\r\n- moved to Guzzle\r\n- user can set own timeout for Botan requests `$telegram->enableBotan('TOKEN', 5)`, defaults to 3\r\n- added shortener usage example\r\n- stated potential usage for `public static $command` in docblock\r\n- fixed botan not working with getUpdates\r\n\r\nOther\r\n- Fixed `Call to a member function getBody() on null` happening on empty or no replies (currently visible on Windows, will be replaced with 'invalid response' exception which is better)\r\n- Fixed code with PHP Code Beautifier and Fixer\r\n- Added example usage of editMessageText \r\n(I think it would bea good idea to make more usage/command examples based on past closed issues)","created_at":"2016-12-26T14:40:53Z","updated_at":"2016-12-27T01:54:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e7b78ad1de44132fb0a962e1f36f1c1c76323edb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365/commits","review_comments_url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365/comments","review_comment_url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/365/comments","statuses_url":"https://api.github.com/repos/akalongman/php-telegram-bot/statuses/987dbf9c139734475a676ebc0f25192f8142d736","head":{"label":"jacklul:botan_and_misc","ref":"botan_and_misc","sha":"987dbf9c139734475a676ebc0f25192f8142d736","user":{"login":"jacklul","id":8418678,"avatar_url":"https://avatars.githubusercontent.com/u/8418678?v=3","gravatar_id":"","url":"https://api.github.com/users/jacklul","html_url":"https://github.com/jacklul","followers_url":"https://api.github.com/users/jacklul/followers","following_url":"https://api.github.com/users/jacklul/following{/other_user}","gists_url":"https://api.github.com/users/jacklul/gists{/gist_id}","starred_url":"https://api.github.com/users/jacklul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacklul/subscriptions","organizations_url":"https://api.github.com/users/jacklul/orgs","repos_url":"https://api.github.com/users/jacklul/repos","events_url":"https://api.github.com/users/jacklul/events{/privacy}","received_events_url":"https://api.github.com/users/jacklul/received_events","type":"User","site_admin":false},"repo":{"id":54883343,"name":"php-telegram-bot","full_name":"jacklul/php-telegram-bot","owner":{"login":"jacklul","id":8418678,"avatar_url":"https://avatars.githubusercontent.com/u/8418678?v=3","gravatar_id":"","url":"https://api.github.com/users/jacklul","html_url":"https://github.com/jacklul","followers_url":"https://api.github.com/users/jacklul/followers","following_url":"https://api.github.com/users/jacklul/following{/other_user}","gists_url":"https://api.github.com/users/jacklul/gists{/gist_id}","starred_url":"https://api.github.com/users/jacklul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacklul/subscriptions","organizations_url":"https://api.github.com/users/jacklul/orgs","repos_url":"https://api.github.com/users/jacklul/repos","events_url":"https://api.github.com/users/jacklul/events{/privacy}","received_events_url":"https://api.github.com/users/jacklul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jacklul/php-telegram-bot","description":"PHP Telegram Bot based on the official Telegram Bot API","fork":true,"url":"https://api.github.com/repos/jacklul/php-telegram-bot","forks_url":"https://api.github.com/repos/jacklul/php-telegram-bot/forks","keys_url":"https://api.github.com/repos/jacklul/php-telegram-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacklul/php-telegram-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacklul/php-telegram-bot/teams","hooks_url":"https://api.github.com/repos/jacklul/php-telegram-bot/hooks","issue_events_url":"https://api.github.com/repos/jacklul/php-telegram-bot/issues/events{/number}","events_url":"https://api.github.com/repos/jacklul/php-telegram-bot/events","assignees_url":"https://api.github.com/repos/jacklul/php-telegram-bot/assignees{/user}","branches_url":"https://api.github.com/repos/jacklul/php-telegram-bot/branches{/branch}","tags_url":"https://api.github.com/repos/jacklul/php-telegram-bot/tags","blobs_url":"https://api.github.com/repos/jacklul/php-telegram-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacklul/php-telegram-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacklul/php-telegram-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacklul/php-telegram-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacklul/php-telegram-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/jacklul/php-telegram-bot/languages","stargazers_url":"https://api.github.com/repos/jacklul/php-telegram-bot/stargazers","contributors_url":"https://api.github.com/repos/jacklul/php-telegram-bot/contributors","subscribers_url":"https://api.github.com/repos/jacklul/php-telegram-bot/subscribers","subscription_url":"https://api.github.com/repos/jacklul/php-telegram-bot/subscription","commits_url":"https://api.github.com/repos/jacklul/php-telegram-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacklul/php-telegram-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacklul/php-telegram-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacklul/php-telegram-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacklul/php-telegram-bot/contents/{+path}","compare_url":"https://api.github.com/repos/jacklul/php-telegram-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacklul/php-telegram-bot/merges","archive_url":"https://api.github.com/repos/jacklul/php-telegram-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacklul/php-telegram-bot/downloads","issues_url":"https://api.github.com/repos/jacklul/php-telegram-bot/issues{/number}","pulls_url":"https://api.github.com/repos/jacklul/php-telegram-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/jacklul/php-telegram-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/jacklul/php-telegram-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacklul/php-telegram-bot/labels{/name}","releases_url":"https://api.github.com/repos/jacklul/php-telegram-bot/releases{/id}","deployments_url":"https://api.github.com/repos/jacklul/php-telegram-bot/deployments","created_at":"2016-03-28T09:59:30Z","updated_at":"2016-03-28T09:59:31Z","pushed_at":"2016-12-26T21:27:30Z","git_url":"git://github.com/jacklul/php-telegram-bot.git","ssh_url":"git@github.com:jacklul/php-telegram-bot.git","clone_url":"https://github.com/jacklul/php-telegram-bot.git","svn_url":"https://github.com/jacklul/php-telegram-bot","homepage":"","size":1110,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"akalongman:develop","ref":"develop","sha":"1c54e2c0e3eaa6eb335671edc02164d03e14147b","user":{"login":"akalongman","id":423050,"avatar_url":"https://avatars.githubusercontent.com/u/423050?v=3","gravatar_id":"","url":"https://api.github.com/users/akalongman","html_url":"https://github.com/akalongman","followers_url":"https://api.github.com/users/akalongman/followers","following_url":"https://api.github.com/users/akalongman/following{/other_user}","gists_url":"https://api.github.com/users/akalongman/gists{/gist_id}","starred_url":"https://api.github.com/users/akalongman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akalongman/subscriptions","organizations_url":"https://api.github.com/users/akalongman/orgs","repos_url":"https://api.github.com/users/akalongman/repos","events_url":"https://api.github.com/users/akalongman/events{/privacy}","received_events_url":"https://api.github.com/users/akalongman/received_events","type":"User","site_admin":false},"repo":{"id":38116958,"name":"php-telegram-bot","full_name":"akalongman/php-telegram-bot","owner":{"login":"akalongman","id":423050,"avatar_url":"https://avatars.githubusercontent.com/u/423050?v=3","gravatar_id":"","url":"https://api.github.com/users/akalongman","html_url":"https://github.com/akalongman","followers_url":"https://api.github.com/users/akalongman/followers","following_url":"https://api.github.com/users/akalongman/following{/other_user}","gists_url":"https://api.github.com/users/akalongman/gists{/gist_id}","starred_url":"https://api.github.com/users/akalongman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akalongman/subscriptions","organizations_url":"https://api.github.com/users/akalongman/orgs","repos_url":"https://api.github.com/users/akalongman/repos","events_url":"https://api.github.com/users/akalongman/events{/privacy}","received_events_url":"https://api.github.com/users/akalongman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akalongman/php-telegram-bot","description":"PHP Telegram Bot based on the official Telegram Bot API","fork":false,"url":"https://api.github.com/repos/akalongman/php-telegram-bot","forks_url":"https://api.github.com/repos/akalongman/php-telegram-bot/forks","keys_url":"https://api.github.com/repos/akalongman/php-telegram-bot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akalongman/php-telegram-bot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akalongman/php-telegram-bot/teams","hooks_url":"https://api.github.com/repos/akalongman/php-telegram-bot/hooks","issue_events_url":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/events{/number}","events_url":"https://api.github.com/repos/akalongman/php-telegram-bot/events","assignees_url":"https://api.github.com/repos/akalongman/php-telegram-bot/assignees{/user}","branches_url":"https://api.github.com/repos/akalongman/php-telegram-bot/branches{/branch}","tags_url":"https://api.github.com/repos/akalongman/php-telegram-bot/tags","blobs_url":"https://api.github.com/repos/akalongman/php-telegram-bot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akalongman/php-telegram-bot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akalongman/php-telegram-bot/git/refs{/sha}","trees_url":"https://api.github.com/repos/akalongman/php-telegram-bot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akalongman/php-telegram-bot/statuses/{sha}","languages_url":"https://api.github.com/repos/akalongman/php-telegram-bot/languages","stargazers_url":"https://api.github.com/repos/akalongman/php-telegram-bot/stargazers","contributors_url":"https://api.github.com/repos/akalongman/php-telegram-bot/contributors","subscribers_url":"https://api.github.com/repos/akalongman/php-telegram-bot/subscribers","subscription_url":"https://api.github.com/repos/akalongman/php-telegram-bot/subscription","commits_url":"https://api.github.com/repos/akalongman/php-telegram-bot/commits{/sha}","git_commits_url":"https://api.github.com/repos/akalongman/php-telegram-bot/git/commits{/sha}","comments_url":"https://api.github.com/repos/akalongman/php-telegram-bot/comments{/number}","issue_comment_url":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/comments{/number}","contents_url":"https://api.github.com/repos/akalongman/php-telegram-bot/contents/{+path}","compare_url":"https://api.github.com/repos/akalongman/php-telegram-bot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akalongman/php-telegram-bot/merges","archive_url":"https://api.github.com/repos/akalongman/php-telegram-bot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akalongman/php-telegram-bot/downloads","issues_url":"https://api.github.com/repos/akalongman/php-telegram-bot/issues{/number}","pulls_url":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls{/number}","milestones_url":"https://api.github.com/repos/akalongman/php-telegram-bot/milestones{/number}","notifications_url":"https://api.github.com/repos/akalongman/php-telegram-bot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akalongman/php-telegram-bot/labels{/name}","releases_url":"https://api.github.com/repos/akalongman/php-telegram-bot/releases{/id}","deployments_url":"https://api.github.com/repos/akalongman/php-telegram-bot/deployments","created_at":"2015-06-26T14:55:57Z","updated_at":"2016-12-27T00:12:49Z","pushed_at":"2016-12-26T21:27:32Z","git_url":"git://github.com/akalongman/php-telegram-bot.git","ssh_url":"git@github.com:akalongman/php-telegram-bot.git","clone_url":"https://github.com/akalongman/php-telegram-bot.git","svn_url":"https://github.com/akalongman/php-telegram-bot","homepage":"","size":1114,"stargazers_count":713,"watchers_count":713,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":232,"mirror_url":null,"open_issues_count":35,"forks":232,"open_issues":35,"watchers":713,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365"},"html":{"href":"https://github.com/akalongman/php-telegram-bot/pull/365"},"issue":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/365"},"comments":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/issues/365/comments"},"review_comments":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365/comments"},"review_comment":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/pulls/365/commits"},"statuses":{"href":"https://api.github.com/repos/akalongman/php-telegram-bot/statuses/987dbf9c139734475a676ebc0f25192f8142d736"}}}}
{"actor":{"display_login":"noplanman"}}