From 7c318e144fbc613e76ef9bb7f9904588e69164c0 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 15 Jan 2026 09:34:40 +0100 Subject: [PATCH] telegram-chat: early exit with :exit --- telegram-chat.rsc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 53ab6c66..a38e63f9 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -3,13 +3,12 @@ # Copyright (c) 2023-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# requires RouterOS, version=7.17 +# requires RouterOS, version=7.22beta1 # requires device-mode, fetch # # use Telegram to chat with your Router and send commands # https://rsc.eworm.de/doc/telegram-chat.md -:local ExitOK false; :onerror Err { :global GlobalConfigReady; :global GlobalFunctionsReady; :retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \ @@ -48,8 +47,7 @@ :global WaitFullyConnected; :if ([ $ScriptLock $ScriptName ] = false) do={ - :set ExitOK true; - :error false; + :exit; } $WaitFullyConnected; @@ -63,8 +61,7 @@ :if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={ $LogPrint warning $ScriptName ("Downloading required certificate failed."); - :set ExitOK true; - :error false; + :exit; } $RandomDelay $TelegramRandomDelay; @@ -89,8 +86,7 @@ :if ($Data = false) do={ $LogPrint warning $ScriptName ("Failed getting updates."); - :set ExitOK true; - :error false; + :exit; } :local JSON [ :deserialize from=json value=$Data ]; @@ -146,8 +142,7 @@ :local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]); :if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={ $LogPrint error $ScriptName ("Failed creating directory!"); - :set ExitOK true; - :error false; + :exit; } $LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command); :execute script=(":do {\n" . $Command . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \ @@ -197,5 +192,5 @@ :set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \ [ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]); } do={ - :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; + :global ExitError; $ExitError true [ :jobname ] $Err; }