From b84ab4b4640345b1c9c69a4ec8669555d9f32f74 Mon Sep 17 00:00:00 2001 From: mercury Date: Fri, 12 May 2023 00:41:38 +0400 Subject: [PATCH] wg timer: delete -> off peer --- app/bot.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/bot.php b/app/bot.php index 6daedf0..abe640b 100644 --- a/app/bot.php +++ b/app/bot.php @@ -98,8 +98,9 @@ class Bot } else { file_put_contents('/logs/debug', var_export($var, true)); } + } else { + $this->send($this->input['chat'], var_export($var, true), $this->input['message_id']); } - $this->send($this->input['chat'], var_export($var, true), $this->input['message_id']); } public function action() @@ -166,6 +167,7 @@ class Bot break; case preg_match('~^/switchClient (?P\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m): $this->switchClient(...explode('_', $m['arg'])); + $this->menu('client', $m['arg']); break; case preg_match('~^/deladmin (\d+)$~', $this->input['callback'], $m): $this->delAdmin($m[1]); @@ -418,15 +420,18 @@ class Bot public function cron() { while (true) { - $clients = $this->readClients(); - if ($clients) { - foreach ($clients as $k => $v) { - if (!empty($v['interface']['## time'])) { - if (strtotime($v['interface']['## time']) < time()) { - $this->deletePeer($k, 0, false); + try { + $clients = $this->readClients(); + if ($clients) { + foreach ($clients as $k => $v) { + if (!empty($v['interface']['## time'])) { + if (strtotime($v['interface']['## time']) < time()) { + $this->switchClient($k); + } } } } + } catch (Exception $e) { } sleep(10); } @@ -581,13 +586,15 @@ class Bot public function switchClient($client) { $clients = $this->readClients(); + $server = $this->readConfig(); if ($clients[$client]['# off']) { unset($clients[$client]['# off']); } else { $clients[$client]['# off'] = 1; + unset($clients[$client]['interface']['## time']); + unset($server['peers'][$client]['## time']); } $this->saveClients($clients); - $server = $this->readConfig(); if (array_key_exists('# PublicKey', $server['peers'][$client])) { foreach ($server['peers'][$client] as $k => $v) { $new[trim(preg_replace('~#~', '', $k, 1))] = $v; @@ -599,7 +606,6 @@ class Bot } $server['peers'][$client] = $new; $this->restartWG($this->createConfig($server)); - $this->menu('client', "{$client}_0"); } public function switchTorrent($page)