From d225e7c03907abd5a3f6f607a422f1a0225824c3 Mon Sep 17 00:00:00 2001 From: mercury Date: Wed, 23 Oct 2024 02:06:35 +0400 Subject: [PATCH] fix double import after update --- app/bot.php | 53 ++++++++++++++++++++++++++++++---------------------- app/init.php | 1 + version | 4 ++++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/bot.php b/app/bot.php index 82bae29..7c7e6ad 100644 --- a/app/bot.php +++ b/app/bot.php @@ -1092,6 +1092,12 @@ class Bot } } + public function cleanQueue() + { + $r = $this->request('deleteWebhook', []); + $r = $this->request('getUpdates', ['offset' => -1]); + } + public function pinAdmin($pin, $unpin = false) { require __DIR__ . '/config.php'; @@ -1787,11 +1793,18 @@ class Bot public function sslip() { - $c = $this->getPacConf(); - if (empty($c['domain'])) { + require __DIR__ . '/config.php'; + $p = $this->getPacConf(); + $ip = getenv('IP'); + $r = $this->send($c['admin'][0], "start $ip"); + + $this->input['chat'] = $c['admin'][0]; + $this->input['message_id'] = $r['result']['message_id']; + if (empty($p['domain'])) { $this->addDomain(str_replace('.', '-', $this->ip) . '.nip.io', 1); $this->setSSL('letsencrypt'); } + $this->menu(dontshowcron: 1); } public function comment($text, $tag) @@ -3842,13 +3855,13 @@ DNS-over-HTTPS with IP: $this->menu('wg', 0); } - public function menu($type = false, $arg = false, $return = false) + public function menu($type = false, $arg = false, $return = false, $dontshowcron = false) { $domain = $this->getPacConf()['domain'] ?: $this->ip; $cron = exec('pgrep -f cron.php'); $menu = [ 'main' => [ - 'text' => 'v' . getenv('VER') . "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show logs/php_error'), + 'text' => 'v' . getenv('VER') . ($dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show logs/php_error')), 'data' => [ [ [ @@ -5724,25 +5737,21 @@ DNS-over-HTTPS with IP: $ip = getenv('IP'); $rm = explode(':', trim(file_get_contents('/update/reload_message'))); $m = file_get_contents('/update/message'); - foreach ($c['admin'] as $k => $v) { - $r = $this->send($v, "start $ip"); - $this->input['chat'] = $v; + if (file_exists($this->update)) { + $r = $this->send($c['admin'][0], "start update"); + $this->input['chat'] = $c['admin'][0]; $this->input['message_id'] = $r['result']['message_id']; - if (file_exists($this->update)) { - if (!empty($m)) { - $this->send($v, "
$m
", $v == $rm[0] ? $rm[1] : 0); - } - $r = $this->send($v, "import settings"); - $this->input['chat'] = $v; - $this->input['message_id'] = $r['result']['message_id']; - $this->input['callback_id'] = $r['result']['message_id']; - if (empty($flag)) { - $this->importFile($this->update); - unlink($this->update); - $flag = true; - } - } else { - $this->menu(); + if (!empty($m)) { + $this->send($c['admin'][0], "
$m
", $rm[1]); + } + $r = $this->send($c['admin'][0], "import settings"); + $this->input['chat'] = $c['admin'][0]; + $this->input['message_id'] = $r['result']['message_id']; + $this->input['callback_id'] = $r['result']['message_id']; + if (empty($flag)) { + $this->importFile($this->update); + unlink($this->update); + $flag = true; } } } diff --git a/app/init.php b/app/init.php index f33a958..a531d2c 100644 --- a/app/init.php +++ b/app/init.php @@ -10,6 +10,7 @@ if ($c['debug']) { } $bot = new Bot($c['key'], $i); +$bot->cleanQueue(); $bot->setwebhook(); $bot->selfUpdate(); $bot->adguardCheckPswd(); diff --git a/version b/version index db0b234..434431f 100644 --- a/version +++ b/version @@ -1,3 +1,7 @@ +23.10.2024 v1.78 +- фикс двойного импорта при обновлении, когда админов больше одного +- рестарт бота сбрасывает очередь сообщений от телеграма +- при старте статус крона не показывается, т.к он еще не успел запуститься 23.10.2024 v1.77 - вывод статуса cron - фикс с отправкой бэкапа при спецсимволах в названии бота