Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
959a76f5
Commit
959a76f5
authored
Jan 09, 2017
by
Armando Lüscher
Committed by
GitHub
Jan 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #387 from noplanman/debug_command
Debug command
parents
4e511e9d
aecd80b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
5 deletions
+140
-5
DebugCommand.php
src/Commands/AdminCommands/DebugCommand.php
+117
-0
Telegram.php
src/Telegram.php
+10
-0
TelegramTest.php
tests/unit/TelegramTest.php
+13
-5
No files found.
src/Commands/AdminCommands/DebugCommand.php
0 → 100644
View file @
959a76f5
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot\Commands\AdminCommands
;
use
Longman\TelegramBot\Commands\AdminCommand
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Request
;
/**
* Admin "/debug" command
*/
class
DebugCommand
extends
AdminCommand
{
/**
* @var string
*/
protected
$name
=
'debug'
;
/**
* @var string
*/
protected
$description
=
'Debug command to help find issues'
;
/**
* @var string
*/
protected
$usage
=
'/debug'
;
/**
* @var string
*/
protected
$version
=
'1.1.0'
;
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
()
{
$pdo
=
DB
::
getPdo
();
$message
=
$this
->
getMessage
();
$chat
=
$message
->
getChat
();
$text
=
strtolower
(
$message
->
getText
(
true
));
$data
=
[
'chat_id'
=>
$chat
->
getId
()];
if
(
$text
!==
'glasnost'
&&
!
$chat
->
isPrivateChat
())
{
$data
[
'text'
]
=
'Only available in a private chat.'
;
return
Request
::
sendMessage
(
$data
);
}
$debug_info
=
[];
$debug_info
[]
=
sprintf
(
'*TelegramBot version:* `%s`'
,
$this
->
telegram
->
getVersion
());
$debug_info
[]
=
sprintf
(
'*Download path:* `%s`'
,
$this
->
telegram
->
getDownloadPath
());
$debug_info
[]
=
sprintf
(
'*Upload path:* `%s`'
,
$this
->
telegram
->
getUploadPath
());
// Commands paths.
$debug_info
[]
=
'*Commands paths:*'
;
$debug_info
[]
=
sprintf
(
'```'
.
PHP_EOL
.
'%s```'
,
json_encode
(
$this
->
telegram
->
getCommandsPaths
(),
JSON_PRETTY_PRINT
|
JSON_UNESCAPED_SLASHES
)
);
$php_bit
=
''
;
PHP_INT_SIZE
===
4
&&
$php_bit
=
' (32bit)'
;
PHP_INT_SIZE
===
8
&&
$php_bit
=
' (64bit)'
;
$debug_info
[]
=
sprintf
(
'*PHP version:* `%1$s%2$s; %3$s; %4$s`'
,
PHP_VERSION
,
$php_bit
,
PHP_SAPI
,
PHP_OS
);
$debug_info
[]
=
sprintf
(
'*Maximum PHP script execution time:* `%d seconds`'
,
ini_get
(
'max_execution_time'
));
$mysql_version
=
$pdo
?
$pdo
->
query
(
'SELECT VERSION() AS version'
)
->
fetchColumn
()
:
null
;
$debug_info
[]
=
sprintf
(
'*MySQL version:* `%s`'
,
$mysql_version
?:
'disabled'
);
$debug_info
[]
=
sprintf
(
'*Operating System:* `%s`'
,
php_uname
());
if
(
isset
(
$_SERVER
[
'SERVER_SOFTWARE'
]))
{
$debug_info
[]
=
sprintf
(
'*Web Server:* `%s`'
,
$_SERVER
[
'SERVER_SOFTWARE'
]);
}
if
(
function_exists
(
'curl_init'
))
{
$curlversion
=
curl_version
();
$debug_info
[]
=
sprintf
(
'*curl version:* `%1$s; %2$s`'
,
$curlversion
[
'version'
],
$curlversion
[
'ssl_version'
]);
}
$webhook_info_title
=
'*Webhook Info:*'
;
try
{
// Check if we're actually using the Webhook method.
if
(
Request
::
getInput
()
===
''
)
{
$debug_info
[]
=
$webhook_info_title
.
' `Using getUpdates method, not Webhook.`'
;
}
else
{
$webhook_info_result
=
json_encode
(
json_decode
(
Request
::
getWebhookInfo
(),
true
)[
'result'
],
JSON_PRETTY_PRINT
|
JSON_UNESCAPED_SLASHES
);
$debug_info
[]
=
$webhook_info_title
;
$debug_info
[]
=
sprintf
(
'```'
.
PHP_EOL
.
'%s```'
,
$webhook_info_result
);
}
}
catch
(
\Exception
$e
)
{
$debug_info
[]
=
$webhook_info_title
.
sprintf
(
' `Failed to get webhook info! (%s)`'
,
$e
->
getMessage
());
}
$data
[
'parse_mode'
]
=
'Markdown'
;
$data
[
'text'
]
=
implode
(
PHP_EOL
,
$debug_info
);
return
Request
::
sendMessage
(
$data
);
}
}
src/Telegram.php
View file @
959a76f5
...
...
@@ -619,6 +619,16 @@ class Telegram
return
$this
;
}
/**
* Return the list of commands paths
*
* @return array
*/
public
function
getCommandsPaths
()
{
return
$this
->
commands_paths
;
}
/**
* Set custom upload path
*
...
...
tests/unit/TelegramTest.php
View file @
959a76f5
...
...
@@ -116,22 +116,30 @@ class TelegramTest extends TestCase
{
$tg
=
$this
->
telegram
;
$this
->
assert
AttributeCount
(
1
,
'commands_paths'
,
$tg
);
$this
->
assert
Count
(
1
,
$tg
->
getCommandsPaths
()
);
$tg
->
addCommandsPath
(
$this
->
custom_commands_paths
[
0
]);
$this
->
assertAttributeCount
(
2
,
'commands_paths'
,
$tg
);
$this
->
assertCount
(
2
,
$tg
->
getCommandsPaths
());
$this
->
assertArraySubset
(
[
$this
->
custom_commands_paths
[
0
]],
$tg
->
getCommandsPaths
()
);
$tg
->
addCommandsPath
(
'/invalid/path'
);
$this
->
assert
AttributeCount
(
2
,
'commands_paths'
,
$tg
);
$this
->
assert
Count
(
2
,
$tg
->
getCommandsPaths
()
);
$tg
->
addCommandsPaths
([
$this
->
custom_commands_paths
[
1
],
$this
->
custom_commands_paths
[
2
],
]);
$this
->
assertAttributeCount
(
4
,
'commands_paths'
,
$tg
);
$this
->
assertCount
(
4
,
$tg
->
getCommandsPaths
());
$this
->
assertArraySubset
(
array_reverse
(
$this
->
custom_commands_paths
),
$tg
->
getCommandsPaths
()
);
$tg
->
addCommandsPath
(
$this
->
custom_commands_paths
[
0
]);
$this
->
assert
AttributeCount
(
4
,
'commands_paths'
,
$tg
);
$this
->
assert
Count
(
4
,
$tg
->
getCommandsPaths
()
);
}
public
function
testGetCommandsList
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment