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
cb8e07db
Unverified
Commit
cb8e07db
authored
Apr 21, 2018
by
Avtandil Kikabidze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove empty response method from client
parent
be3f6059
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
31 deletions
+36
-31
Command.php
src/Commands/Command.php
+4
-3
SystemCommand.php
src/Commands/SystemCommand.php
+2
-1
GenericmessageCommand.php
src/Commands/SystemCommands/GenericmessageCommand.php
+3
-2
Kernel.php
src/Console/Kernel.php
+6
-7
Client.php
src/Http/Client.php
+0
-14
Response.php
src/Http/Response.php
+15
-1
Telegram.php
src/Telegram.php
+2
-1
HiddenCommand.php
tests/unit/Commands/CustomTestCommands/HiddenCommand.php
+2
-1
VisibleCommand.php
tests/unit/Commands/CustomTestCommands/VisibleCommand.php
+2
-1
No files found.
src/Commands/Command.php
View file @
cb8e07db
...
...
@@ -17,6 +17,7 @@ use Longman\TelegramBot\Entities\InlineQuery;
use
Longman\TelegramBot\Entities\Message
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Response
;
use
Longman\TelegramBot\Telegram
;
/**
...
...
@@ -167,7 +168,7 @@ abstract class Command
]);
}
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
return
$this
->
execute
();
...
...
@@ -404,7 +405,7 @@ abstract class Command
],
$data
));
}
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
/**
...
...
@@ -424,6 +425,6 @@ abstract class Command
],
$data
));
}
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
}
src/Commands/SystemCommand.php
View file @
cb8e07db
...
...
@@ -11,6 +11,7 @@
namespace
Longman\TelegramBot\Commands
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Response
;
abstract
class
SystemCommand
extends
Command
{
...
...
@@ -25,6 +26,6 @@ abstract class SystemCommand extends Command
public
function
execute
()
{
//System command, return empty ServerResponse by default
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
}
src/Commands/SystemCommands/GenericmessageCommand.php
View file @
cb8e07db
...
...
@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands;
use
Longman\TelegramBot\Commands\SystemCommand
;
use
Longman\TelegramBot\Conversation
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Response
;
/**
* Generic message command
...
...
@@ -47,7 +48,7 @@ class GenericmessageCommand extends SystemCommand
public
function
executeNoDb
()
{
//Do nothing
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
/**
...
...
@@ -69,6 +70,6 @@ class GenericmessageCommand extends SystemCommand
return
$this
->
telegram
->
executeCommand
(
$command
);
}
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
}
src/Console/Kernel.php
View file @
cb8e07db
...
...
@@ -11,7 +11,6 @@
namespace
Longman\TelegramBot\Console
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Entities\Update
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Request
;
use
Longman\TelegramBot\Http\Response
;
...
...
@@ -57,18 +56,18 @@ class Kernel
'ok'
=>
false
,
'description'
=>
'getUpdates needs MySQL connection! (This can be overridden - see documentation)'
,
],
$this
->
bot_username
$this
->
app
->
getBotUsername
()
);
}
$offset
=
0
;
//Take custom input into account.
//
Take custom input into account.
if
(
$custom_input
=
$this
->
app
->
getCustomInput
())
{
$response
=
new
Response
(
json_decode
(
$custom_input
,
true
),
$this
->
app
->
getBotUsername
());
}
else
{
if
(
DB
::
isDbConnected
())
{
//Get last update id from the database
//
Get last update id from the database
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
...
...
@@ -91,14 +90,14 @@ class Kernel
if
(
$response
->
isOk
())
{
$results
=
$response
->
getResult
();
//Process all updates
/** @var Update $result */
//
Process all updates
/** @var
\Longman\TelegramBot\Entities\
Update $result */
foreach
(
$results
as
$result
)
{
$this
->
app
->
processUpdate
(
$result
);
}
if
(
!
DB
::
isDbConnected
()
&&
!
$custom_input
&&
$this
->
app
->
last_update_id
!==
null
&&
$offset
===
0
)
{
//Mark update(s) as read after handling
//
Mark update(s) as read after handling
Client
::
getUpdates
(
[
'offset'
=>
$this
->
app
->
last_update_id
+
1
,
...
...
src/Http/Client.php
View file @
cb8e07db
...
...
@@ -625,20 +625,6 @@ class Client
return
call_user_func_array
(
'static::send'
,
$data
);
}
/**
* Return an empty Server Response
*
* No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution
*
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
static
function
emptyResponse
()
{
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
],
null
);
}
/**
* Send message to all active chats
*
...
...
src/Http/Response.php
View file @
cb8e07db
...
...
@@ -34,7 +34,7 @@ class Response
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
__construct
(
array
$data
,
$bot_username
)
public
function
__construct
(
array
$data
,
$bot_username
=
''
)
{
// Make sure we don't double-save the raw_data
unset
(
$data
[
'raw_data'
]);
...
...
@@ -227,4 +227,18 @@ class Response
return
$results
;
}
/**
* Return an empty Server Response
*
* No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution
*
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
static
function
createEmpty
()
{
return
new
static
([
'ok'
=>
true
,
'result'
=>
true
]);
}
}
src/Telegram.php
View file @
cb8e07db
...
...
@@ -22,6 +22,7 @@ use Longman\TelegramBot\Exception\TelegramException;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Kernel
;
use
Longman\TelegramBot\Http\Request
;
use
Longman\TelegramBot\Http\Response
;
use
PDO
;
use
RecursiveDirectoryIterator
;
use
RecursiveIteratorIterator
;
...
...
@@ -462,7 +463,7 @@ class Telegram extends Container
if
(
$last_id
&&
count
(
$last_id
)
===
1
)
{
TelegramLog
::
debug
(
'Duplicate update received, processing aborted!'
);
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
DB
::
insertRequest
(
$this
->
update
);
...
...
tests/unit/Commands/CustomTestCommands/HiddenCommand.php
View file @
cb8e07db
...
...
@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use
Longman\TelegramBot\Commands\UserCommand
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Response
;
/**
* Test "/hidden" command to test $show_in_help
...
...
@@ -51,6 +52,6 @@ class HiddenCommand extends UserCommand
*/
public
function
execute
()
{
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
}
tests/unit/Commands/CustomTestCommands/VisibleCommand.php
View file @
cb8e07db
...
...
@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use
Longman\TelegramBot\Commands\UserCommand
;
use
Longman\TelegramBot\Http\Client
;
use
Longman\TelegramBot\Http\Response
;
/**
* Test "/visible" command to test $show_in_help
...
...
@@ -51,6 +52,6 @@ class VisibleCommand extends UserCommand
*/
public
function
execute
()
{
return
Client
::
emptyResponse
(
);
return
new
Response
([
'ok'
=>
true
,
'result'
=>
true
]
);
}
}
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