Skip to content

Commit 82c0c3a

Browse files
authored
Merge pull request #25 from noplanman/use_stable_ip_library
Use more stable `longman/ip-tools` for IP matching.
2 parents b4485ae + 1e4c358 commit 82c0c3a

File tree

5 files changed

+64
-78
lines changed

5 files changed

+64
-78
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
66
## [Unreleased]
77
### Added
88
### Changed
9+
- Use more stable `longman/ip-tools` for IP matching.
910
### Deprecated
1011
### Removed
1112
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ try {
158158

159159
### Set vital bot parameters
160160

161-
The only vital parameters is the API key:
161+
The only vital parameter is the API key:
162162

163163
```php
164164
$bot = new BotManager([

composer.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
"role": "Developer"
1818
}
1919
],
20-
"repositories": [
21-
{
22-
"type": "vcs",
23-
"url": "https://github.com/noplanman/Utils-IP-Tools"
24-
}
25-
],
2620
"require": {
2721
"php": "^7.0",
2822
"longman/telegram-bot": "^0.44",
29-
"allty/utils-ip": "dev-master"
23+
"longman/ip-tools": "^1.2"
3024
},
3125
"require-dev": {
3226
"jakub-onderka/php-parallel-lint": "^0.9.2",

composer.lock

Lines changed: 58 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BotManager.php

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

1111
namespace TelegramBot\TelegramBotManager;
1212

13-
use Allty\Utils\IpTools;
13+
use Longman\IPTools\Ip;
1414
use Longman\TelegramBot\Entities;
1515
use Longman\TelegramBot\Request;
1616
use Longman\TelegramBot\Telegram;
@@ -519,16 +519,9 @@ public function isValidRequest(): bool
519519
}
520520
}
521521

522-
$valid_ips = array_merge(
522+
return Ip::match($ip, array_merge(
523523
[self::TELEGRAM_IP_RANGE],
524524
(array) $this->params->getBotParam('valid_ips', [])
525-
);
526-
foreach ($valid_ips as $valid_ip) {
527-
if (IpTools::ipInRange($ip, $valid_ip)) {
528-
return true;
529-
}
530-
}
531-
532-
return false;
525+
));
533526
}
534527
}

0 commit comments

Comments
 (0)