Skip to content

Commit

Permalink
update: add new configurations params [limit, allowed updates]
Browse files Browse the repository at this point in the history
AmirHkrg committed Oct 7, 2024
1 parent f38b3f5 commit 85a2b25
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Updates.php
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ trait Updates
private string $update_type;
private float $polling_sleep_time;
private int $polling_timeout;
private int $polling_limit;
private array $polling_allowed_updates;

public function __construct()
{
@@ -61,9 +63,12 @@ public function __construct()
: ($_ENV[$key] ?? $default);
};

$this->update_type = $getConfigValue('UPDATE_TYPE', 'sync', 'bot');
$this->polling_sleep_time = $getConfigValue('POLLING_SLEEP_TIME', 0.5, 'bot');
$this->polling_timeout = $getConfigValue('POLLING_TIMEOUT', 100, 'bot');
$this->update_type = $getConfigValue('update_type', 'sync', 'laraquest');
$this->polling_sleep_time = $getConfigValue('sleep_interval', 0.5, 'laraquest.polling');
$this->polling_timeout = $getConfigValue('timeout', 100, 'laraquest.polling');
$this->polling_limit = $getConfigValue('limit', 100, 'laraquest.polling');
$allowed_updates = $getConfigValue('allow_updates', ["*"], 'laraquest.polling');
$this->polling_allowed_updates = $allowed_updates === ["*"] ? null : $allowed_updates;
}
public function __get($name)
{
@@ -89,7 +94,10 @@ public static function polling(callable $callback): void

try {
while (true){
$updates = $polling->getUpdates($lastUpdateId + 1, timeout: $polling->polling_timeout)['result'];
$updates = $polling->getUpdates(
$lastUpdateId + 1, $polling->polling_limit,
$polling->polling_timeout, $polling->polling_allowed_updates
)['result'];

foreach ($updates as $update){
$lastUpdateId = $update['update_id'];

0 comments on commit 85a2b25

Please sign in to comment.