1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the TelegramBot package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Longman\TelegramBot\Commands\AdminCommands; |
12
|
|
|
|
13
|
|
|
use Longman\TelegramBot\Commands\AdminCommand; |
14
|
|
|
use Longman\TelegramBot\DB; |
15
|
|
|
use Longman\TelegramBot\Request; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Admin "/debug" command |
19
|
|
|
*/ |
20
|
|
|
class DebugCommand extends AdminCommand |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $name = 'debug'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Debug command to help find issues'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $usage = '/debug'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $version = '1.0.0'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Command execute method |
44
|
|
|
* |
45
|
|
|
* @return mixed |
46
|
|
|
* @throws \Longman\TelegramBot\Exception\TelegramException |
47
|
|
|
*/ |
48
|
|
|
public function execute() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$pdo = DB::getPdo(); |
51
|
|
|
$message = $this->getMessage(); |
52
|
|
|
$chat_id = $message->getChat()->getId(); |
53
|
|
|
|
54
|
|
|
$debug_info = []; |
55
|
|
|
|
56
|
|
|
$debug_info[] = sprintf('_TelegramBot version_: `%s`', $this->telegram->getVersion()); |
57
|
|
|
|
58
|
|
|
$php_bit = ''; |
59
|
|
|
PHP_INT_SIZE === 4 && $php_bit = ' (32bit)'; |
60
|
|
|
PHP_INT_SIZE === 8 && $php_bit = ' (64bit)'; |
61
|
|
|
$debug_info[] = sprintf('_PHP version_: `%1$s%2$s; %3$s; %4$s`', PHP_VERSION, $php_bit, PHP_SAPI, PHP_OS); |
62
|
|
|
$debug_info[] = sprintf('_Maximum PHP script execution time_: `%d seconds`', ini_get('max_execution_time')); |
63
|
|
|
|
64
|
|
|
$mysql_version = $pdo ? $pdo->query('SELECT VERSION() AS version')->fetchColumn() : null; |
65
|
|
|
$debug_info[] = sprintf('_MySQL version_: `%s`', $mysql_version ?: 'disabled'); |
66
|
|
|
|
67
|
|
|
$debug_info[] = sprintf('_Operating System_: `%s`', php_uname()); |
68
|
|
|
|
69
|
|
|
if (isset($_SERVER['SERVER_SOFTWARE'])) { |
70
|
|
|
$debug_info[] = sprintf('_Web Server_: `%s`', $_SERVER['SERVER_SOFTWARE']); |
71
|
|
|
} |
72
|
|
|
if (function_exists('curl_init')) { |
73
|
|
|
$curlversion = curl_version(); |
74
|
|
|
$debug_info[] = sprintf('_curl version_: `%1$s; %2$s`', $curlversion['version'], $curlversion['ssl_version']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$debug_info[] = '_Webhook Info_:'; |
78
|
|
|
try { |
79
|
|
|
$webhook_info = json_encode(json_decode(Request::getWebhookInfo(), true)['result'], JSON_PRETTY_PRINT); |
80
|
|
|
} catch (\Exception $e) { |
81
|
|
|
$webhook_info = sprintf('Failed to get webhook info! (%s)', $e->getMessage()); |
82
|
|
|
} |
83
|
|
|
$debug_info[] = sprintf("```\n%s\n```", $webhook_info); |
84
|
|
|
|
85
|
|
|
$data = [ |
86
|
|
|
'chat_id' => $chat_id, |
87
|
|
|
'parse_mode' => 'Markdown', |
88
|
|
|
'text' => implode(PHP_EOL, $debug_info), |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
return Request::sendMessage($data); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: