Skip to content

Commit f0afb26

Browse files
committed
Rename botname to bot_username, like in core 0.42.0.
Fix coding style. Add changelog.
1 parent 3fa47d8 commit f0afb26

File tree

10 files changed

+106
-55
lines changed

10 files changed

+106
-55
lines changed

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Changelog
2+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
3+
4+
## [Unreleased]
5+
### Added
6+
- Changelog.
7+
### Changed
8+
- (!) Rename vital parameter `botname` to `bot_username` everywhere.
9+
### Fixed
10+
- Some code style issues.
11+
12+
## [0.42.0] - 2017-04-10
13+
### Changed
14+
- Move to PHP Telegram Bot organisation.
15+
- Mirror version with core library.
16+
- Update repository links.
17+
### Fixed
18+
- Readme formatting.
19+
20+
## [0.4.0] - 2017-02-26
21+
### Added
22+
- Latest Telegram Bot limiter functionality.
23+
### Fixed
24+
- Travis tests, using MariaDB instead of MySQL.
25+
26+
## [0.3.1] - 2017-01-04
27+
### Fixed
28+
- Make CLI usable again after setting up Telegram API IP address limitations.
29+
30+
## [0.3.0] - 2016-12-25
31+
### Added
32+
- Latest changes from PHP Telegram API bot.
33+
### Security
34+
- Request validation to secure the script to allow only Telegram API IPs of executing the webhook handle.
35+
36+
## [0.2.1] - 2016-10-16
37+
### Added
38+
- Interval between updates can be set via parameter.
39+
40+
## [0.2] - 2016-09-16
41+
### Changed
42+
- Force PHP7.
43+
44+
## [0.1.1] - 2016-08-20
45+
### Fixed
46+
- Tiny conditional fix to correct the output.
47+
48+
## [0.1] - 2016-08-20
49+
### Added
50+
- First minor version that contains the basic functionality.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ require __DIR__ . '/vendor/autoload.php';
114114
try {
115115
$bot = new BotManager([
116116
// Vitals!
117-
'api_key' => '12345:my_api_key',
118-
'botname' => 'my_own_bot',
119-
'secret' => 'super_secret',
117+
'api_key' => '12345:my_api_key',
118+
'bot_username' => 'my_own_bot',
119+
'secret' => 'super_secret',
120120

121121
// Extras.
122-
'webhook' => 'https://example.com/manager.php',
122+
'webhook' => 'https://example.com/manager.php',
123123
]);
124124
$bot->run();
125125
} catch (\Exception $e) {
@@ -131,7 +131,7 @@ try {
131131

132132
The vital parameters are:
133133
- Bot API key
134-
- Bot name
134+
- Bot username
135135
- A secret
136136

137137
What secret you ask? Well, this is a user-defined key that is required to execute any of the library features.

src/Action.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*
@@ -52,7 +52,7 @@ public function __construct($action = 'handle')
5252
*/
5353
public function isAction($actions): bool
5454
{
55-
return in_array($this->action, (array)$actions, true);
55+
return in_array($this->action, (array) $actions, true);
5656
}
5757

5858
/**

src/BotManager.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*
@@ -60,6 +60,7 @@ class BotManager
6060
* @param array $params
6161
*
6262
* @throws \InvalidArgumentException
63+
* @throws \Longman\TelegramBot\Exception\TelegramException
6364
*/
6465
public function __construct(array $params)
6566
{
@@ -69,7 +70,7 @@ public function __construct(array $params)
6970
// Set up a new Telegram instance.
7071
$this->telegram = new Telegram(
7172
$this->params->getBotParam('api_key'),
72-
$this->params->getBotParam('botname')
73+
$this->params->getBotParam('bot_username')
7374
);
7475
}
7576

@@ -324,7 +325,7 @@ public function getLoopTime(): int
324325
return 604800; // Default to 7 days.
325326
}
326327

327-
return max(0, (int)$loop_time);
328+
return max(0, (int) $loop_time);
328329
}
329330

330331
/**
@@ -341,7 +342,7 @@ public function getLoopInterval(): int
341342
}
342343

343344
// Minimum interval is 1 second.
344-
return max(1, (int)$interval_time);
345+
return max(1, (int) $interval_time);
345346
}
346347

347348
/**
@@ -382,7 +383,7 @@ public function handleGetUpdates(): self
382383

383384
$response = $this->telegram->handleGetUpdates();
384385
if ($response->isOk()) {
385-
$results = array_filter((array)$response->getResult());
386+
$results = array_filter((array) $response->getResult());
386387

387388
$output .= sprintf('Updates processed: %d' . PHP_EOL, count($results));
388389

@@ -468,9 +469,9 @@ public function isValidRequest(): bool
468469
}
469470
}
470471

471-
$lower_dec = (float)sprintf('%u', ip2long(self::TELEGRAM_IP_LOWER));
472-
$upper_dec = (float)sprintf('%u', ip2long(self::TELEGRAM_IP_UPPER));
473-
$ip_dec = (float)sprintf('%u', ip2long($ip));
472+
$lower_dec = (float) sprintf('%u', ip2long(self::TELEGRAM_IP_LOWER));
473+
$upper_dec = (float) sprintf('%u', ip2long(self::TELEGRAM_IP_UPPER));
474+
$ip_dec = (float) sprintf('%u', ip2long($ip));
474475

475476
return $ip_dec >= $lower_dec && $ip_dec <= $upper_dec;
476477
}

src/Params.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*
@@ -27,7 +27,7 @@ class Params
2727
*/
2828
private static $valid_vital_bot_params = [
2929
'api_key',
30-
'botname',
30+
'bot_username',
3131
'secret',
3232
];
3333

@@ -68,7 +68,7 @@ class Params
6868
* Params constructor.
6969
*
7070
* api_key (string) Telegram Bot API key
71-
* botname (string) Telegram Bot name
71+
* bot_username (string) Telegram Bot username
7272
* secret (string) Secret string to validate calls
7373
* validate_request (bool) Only allow webhook access from valid Telegram API IPs
7474
* webhook (string) URI of the webhook

tests/TelegramBotManager/Tests/ActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*

tests/TelegramBotManager/Tests/BotManagerTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*
@@ -32,10 +32,10 @@ class BotManagerTest extends \PHPUnit\Framework\TestCase
3232
public static function setUpBeforeClass()
3333
{
3434
self::$live_params = [
35-
'api_key' => getenv('API_KEY'),
36-
'botname' => getenv('BOTNAME'),
37-
'secret' => 'super-secret',
38-
'mysql' => [
35+
'api_key' => getenv('API_KEY'),
36+
'bot_username' => getenv('BOT_USERNAME'),
37+
'secret' => 'super-secret',
38+
'mysql' => [
3939
'host' => PHPUNIT_DB_HOST,
4040
'database' => PHPUNIT_DB_NAME,
4141
'user' => PHPUNIT_DB_USER,
@@ -77,7 +77,7 @@ public function testNoVitalsFail()
7777
*/
7878
public function testSomeVitalsFail()
7979
{
80-
new BotManager(['api_key' => '12345:api_key', 'botname' => 'testbot']);
80+
new BotManager(['api_key' => '12345:api_key', 'bot_username' => 'testbot']);
8181
}
8282

8383
public function testVitalsSuccess()
@@ -92,7 +92,7 @@ public function testValidTelegramObject()
9292
$telegram = $bot->getTelegram();
9393

9494
self::assertInstanceOf(Telegram::class, $telegram);
95-
self::assertSame(ParamsTest::$demo_vital_params['botname'], $telegram->getBotName());
95+
self::assertSame(ParamsTest::$demo_vital_params['bot_username'], $telegram->getBotUsername());
9696
self::assertSame(ParamsTest::$demo_vital_params['api_key'], $telegram->getApiKey());
9797
}
9898

@@ -158,31 +158,31 @@ public function testValidateAndSetWebhookSuccess()
158158
$botManager,
159159
'telegram',
160160
$this->getMockBuilder(Telegram::class)
161-
->disableOriginalConstructor()
162-
->setMethods(['setWebhook', 'deleteWebhook', 'getDescription'])
163-
->getMock()
161+
->disableOriginalConstructor()
162+
->setMethods(['setWebhook', 'deleteWebhook', 'getDescription'])
163+
->getMock()
164164
);
165165

166166
$telegram = $botManager->getTelegram();
167167

168168
/** @var \PHPUnit_Framework_MockObject_MockObject $telegram */
169169
$telegram->expects(static::any())
170-
->method('setWebhook')
171-
->with('https://web/hook.php?a=handle&s=secret_12345')
172-
->will(static::returnSelf());
170+
->method('setWebhook')
171+
->with('https://web/hook.php?a=handle&s=secret_12345')
172+
->will(static::returnSelf());
173173
$telegram->expects(static::any())
174-
->method('deleteWebhook')
175-
->will(static::returnSelf());
174+
->method('deleteWebhook')
175+
->will(static::returnSelf());
176176
$telegram->expects(static::any())
177-
->method('getDescription')
178-
->will(static::onConsecutiveCalls(
179-
'Webhook was set', // set
180-
'Webhook is already set',
181-
'Webhook was deleted', // reset
182-
'Webhook was set',
183-
'Webhook was deleted', //unset
184-
'Webhook is already deleted'
185-
));
177+
->method('getDescription')
178+
->will(static::onConsecutiveCalls(
179+
'Webhook was set', // set
180+
'Webhook is already set',
181+
'Webhook was deleted', // reset
182+
'Webhook was set',
183+
'Webhook was deleted', //unset
184+
'Webhook is already deleted'
185+
));
186186

187187
TestHelpers::setObjectProperty($botManager->getAction(), 'action', 'set');
188188
$output = $botManager->validateAndSetWebhook()->getOutput();

tests/TelegramBotManager/Tests/ParamsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*
@@ -18,9 +18,9 @@ class ParamsTest extends \PHPUnit\Framework\TestCase
1818
* @var array Demo vital parameters.
1919
*/
2020
public static $demo_vital_params = [
21-
'api_key' => '12345:api_key',
22-
'botname' => 'test_bot',
23-
'secret' => 'secret_12345',
21+
'api_key' => '12345:api_key',
22+
'bot_username' => 'test_bot',
23+
'secret' => 'secret_12345',
2424
];
2525

2626
/**
@@ -70,16 +70,16 @@ public function testConstruct()
7070
public function testConstructWithoutApiKey()
7171
{
7272
new Params([
73-
'botname' => 'test_bot',
74-
'secret' => 'secret_12345',
73+
'bot_username' => 'test_bot',
74+
'secret' => 'secret_12345',
7575
]);
7676
}
7777

7878
/**
7979
* @expectedException \InvalidArgumentException
80-
* @expectedExceptionMessage Some vital info is missing: botname
80+
* @expectedExceptionMessage Some vital info is missing: bot_username
8181
*/
82-
public function testConstructWithoutBotname()
82+
public function testConstructWithoutBotUsername()
8383
{
8484
new Params([
8585
'api_key' => '12345:api_key',
@@ -94,8 +94,8 @@ public function testConstructWithoutBotname()
9494
public function testConstructWithoutSecret()
9595
{
9696
new Params([
97-
'api_key' => '12345:api_key',
98-
'botname' => 'test_bot',
97+
'api_key' => '12345:api_key',
98+
'bot_username' => 'test_bot',
9999
]);
100100
}
101101

tests/TelegramBotManager/Tests/TestHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types=1);
22
/**
33
* This file is part of the TelegramBotManager package.
44
*

0 commit comments

Comments
 (0)