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
13d32053
Commit
13d32053
authored
Feb 09, 2018
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further optimizations
parent
ef495246
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
13 deletions
+10
-13
Telegram.php
src/Telegram.php
+10
-13
No files found.
src/Telegram.php
View file @
13d32053
...
...
@@ -150,7 +150,7 @@ class Telegram
*
* @var integer
*/
protected
$last_update_id
=
-
1
;
protected
$last_update_id
=
null
;
/**
* Telegram constructor.
...
...
@@ -345,22 +345,24 @@ class Telegram
);
}
$offset
=
0
;
//Take custom input into account.
if
(
$custom_input
=
$this
->
getCustomInput
())
{
$response
=
new
ServerResponse
(
json_decode
(
$custom_input
,
true
),
$this
->
bot_username
);
}
else
{
if
(
DB
::
isDbConnected
())
{
//
DB Query
//
Get last update id from the database
$last_update
=
DB
::
selectTelegramUpdate
(
1
);
$last_update
=
reset
(
$last_update
);
$this
->
last_update_id
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
:
-
1
;
$this
->
last_update_id
=
isset
(
$last_update
[
'id'
])
?
$last_update
[
'id'
]
:
null
;
}
//As explained in the telegram bot api documentation
$offset
=
$this
->
last_update_id
+
1
;
if
(
$this
->
last_update_id
!==
null
)
{
$offset
=
$this
->
last_update_id
+
1
;
//As explained in the telegram bot API documentation
}
//Finally, get updates from Telegram!
$response
=
Request
::
getUpdates
(
[
'offset'
=>
$offset
,
...
...
@@ -373,19 +375,13 @@ class Telegram
if
(
$response
->
isOk
())
{
$results
=
$response
->
getResult
();
$mark_as_read
=
false
;
if
(
!
DB
::
isDbConnected
()
&&
$this
->
last_update_id
<=
0
)
{
$mark_as_read
=
true
;
}
//Process all updates
/** @var Update $result */
foreach
(
$results
as
$result
)
{
$this
->
processUpdate
(
$result
);
$this
->
last_update_id
=
$result
->
getUpdateId
();
//Remember which update was handled after processing each one of them
}
if
(
!
DB
::
isDbConnected
()
&&
$mark_as_read
)
{
if
(
!
DB
::
isDbConnected
()
&&
!
$custom_input
&&
$this
->
last_update_id
!==
null
&&
$offset
===
0
)
{
//Mark update(s) as read after handling
Request
::
getUpdates
(
[
...
...
@@ -454,6 +450,7 @@ class Telegram
public
function
processUpdate
(
Update
$update
)
{
$this
->
update
=
$update
;
$this
->
last_update_id
=
$update
->
getUpdateId
();
//If all else fails, it's a generic message.
$command
=
'genericmessage'
;
...
...
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