Skip to content

Commit df0ec8c

Browse files
committed
Add the new limiter to the spec.
Allow for config options that get set on Request directly.
1 parent 1d25cba commit df0ec8c

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/BotManager.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace NPM\TelegramBotManager;
1212

1313
use Longman\TelegramBot\Entities;
14+
use Longman\TelegramBot\Request;
1415
use Longman\TelegramBot\Telegram;
1516
use Longman\TelegramBot\TelegramLog;
1617

@@ -245,7 +246,7 @@ private function handleOutput($output): self
245246
*/
246247
public function setBotExtras(): self
247248
{
248-
$simple_extras = [
249+
$telegram_extras = [
249250
'admins' => 'enableAdmins',
250251
'mysql' => 'enableMySql',
251252
'botan_token' => 'enableBotan',
@@ -254,14 +255,25 @@ public function setBotExtras(): self
254255
'download_path' => 'setDownloadPath',
255256
'upload_path' => 'setUploadPath',
256257
];
257-
// For simple extras, just pass the single param value to the Telegram method.
258-
foreach ($simple_extras as $param_key => $method) {
258+
// For telegram extras, just pass the single param value to the Telegram method.
259+
foreach ($telegram_extras as $param_key => $method) {
259260
$param = $this->params->getBotParam($param_key);
260261
if (null !== $param) {
261262
$this->telegram->$method($param);
262263
}
263264
}
264265

266+
$request_extras = [
267+
'limiter' => 'setLimiter',
268+
];
269+
// For request extras, just pass the single param value to the Request method.
270+
foreach ($request_extras as $param_key => $method) {
271+
$param = $this->params->getBotParam($param_key);
272+
if (null !== $param) {
273+
Request::$method($param);
274+
}
275+
}
276+
265277
$command_configs = $this->params->getBotParam('command_configs');
266278
if (is_array($command_configs)) {
267279
/** @var array $command_configs */

src/Params.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Params
4141
'max_connections',
4242
'allowed_updates',
4343
'logging',
44+
'limiter',
4445
'admins',
4546
'mysql',
4647
'download_path',

tests/TelegramBotManager/Tests/BotManagerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace NPM\TelegramBotManager\Tests;
1212

13+
use Longman\TelegramBot\Request;
1314
use Longman\TelegramBot\Telegram;
1415
use Longman\TelegramBot\TelegramLog;
1516
use NPM\TelegramBotManager\BotManager;
@@ -332,6 +333,7 @@ public function testGetLoopInterval()
332333
public function testSetBotExtras()
333334
{
334335
$extras = [
336+
'limiter' => false,
335337
'admins' => [1, 2, 3],
336338
'download_path' => __DIR__ . '/Download',
337339
'upload_path' => __DIR__ . '/Upload',
@@ -344,6 +346,7 @@ public function testSetBotExtras()
344346
$botManager->setBotExtras();
345347
$telegram = $botManager->getTelegram();
346348

349+
self::assertAttributeEquals($extras['limiter'], 'limiter_enabled', Request::class);
347350
self::assertEquals($extras['admins'], $telegram->getAdminList());
348351
self::assertEquals($extras['download_path'], $telegram->getDownloadPath());
349352
self::assertEquals($extras['upload_path'], $telegram->getUploadPath());

tests/TelegramBotManager/Tests/ParamsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ParamsTest extends \PHPUnit_Framework_TestCase
3232
'certificate' => __DIR__ . '/server.crt',
3333
'max_connections' => 20,
3434
'allowed_updates' => ['message', 'edited_channel_post', 'callback_query'],
35+
'limiter' => false,
3536
'admins' => [1],
3637
'mysql' => [
3738
'host' => '127.0.0.1',

0 commit comments

Comments
 (0)