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
899b79ba
Commit
899b79ba
authored
Feb 07, 2017
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code readability
parent
b2e1c34c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
Request.php
src/Request.php
+14
-5
No files found.
src/Request.php
View file @
899b79ba
...
@@ -1029,21 +1029,30 @@ class Request
...
@@ -1029,21 +1029,30 @@ class Request
'editMessageReplyMarkup'
,
'editMessageReplyMarkup'
,
];
];
if
((
isset
(
$data
[
'chat_id'
])
||
isset
(
$data
[
'inline_message_id'
]))
&&
in_array
(
$action
,
$limited_methods
))
{
$chat_id
=
isset
(
$data
[
'chat_id'
])
?
$data
[
'chat_id'
]
:
null
;
$inline_message_id
=
isset
(
$data
[
'inline_message_id'
])
?
$data
[
'inline_message_id'
]
:
null
;
if
((
$chat_id
||
$inline_message_id
)
&&
in_array
(
$action
,
$limited_methods
))
{
$timeout
=
60
;
$timeout
=
60
;
while
(
true
)
{
while
(
true
)
{
if
(
$timeout
<=
0
)
{
if
(
$timeout
<=
0
)
{
throw
new
TelegramException
(
'Timed out while waiting for a request s
l
ot!'
);
throw
new
TelegramException
(
'Timed out while waiting for a request s
p
ot!'
);
}
}
$requests
=
DB
::
getTelegramRequestCount
(
(
isset
(
$data
[
'chat_id'
])
?
$data
[
'chat_id'
]
:
null
),
(
isset
(
$data
[
'inline_message_id'
])
?
$data
[
'inline_message_id'
]
:
null
)
);
$requests
=
DB
::
getTelegramRequestCount
(
$chat_id
,
$inline_message_id
);
if
(
$requests
[
'LIMIT_PER_SEC'
]
<=
0
&&
((
isset
(
$data
[
'inline_message_id'
])
&&
$requests
[
'LIMIT_PER_SEC_ALL'
]
<
30
)
||
(
isset
(
$data
[
'chat_id'
])
&&
$data
[
'chat_id'
]
>
0
&&
$requests
[
'LIMIT_PER_SEC_ALL'
]
<
30
)
||
(
isset
(
$data
[
'chat_id'
])
&&
$data
[
'chat_id'
]
<
0
&&
$requests
[
'LIMIT_PER_MINUTE'
]
<
20
)))
{
if
(
$requests
[
'LIMIT_PER_SEC'
]
==
0
&&
// No more than one message per second inside a particular chat
(
((
$chat_id
>
0
||
$inline_message_id
)
&&
$requests
[
'LIMIT_PER_SEC_ALL'
]
<
30
)
||
// No more than 30 messages per second globally
(
$chat_id
<
0
&&
$requests
[
'LIMIT_PER_MINUTE'
]
<
20
)
// No more than 20 messages per minute for group chats
)
)
{
break
;
break
;
}
}
$timeout
=
$timeout
-
1
;
$timeout
--
;
sleep
(
1
);
sleep
(
1
);
}
}
...
...
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