mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-01-17 22:49:33 +00:00
telegram-chat: early exit with :exit
This commit is contained in:
parent
309d17e81a
commit
7c318e144f
1 changed files with 6 additions and 11 deletions
|
|
@ -3,13 +3,12 @@
|
||||||
# Copyright (c) 2023-2026 Christian Hesse <mail@eworm.de>
|
# Copyright (c) 2023-2026 Christian Hesse <mail@eworm.de>
|
||||||
# https://rsc.eworm.de/COPYING.md
|
# https://rsc.eworm.de/COPYING.md
|
||||||
#
|
#
|
||||||
# requires RouterOS, version=7.17
|
# requires RouterOS, version=7.22beta1
|
||||||
# requires device-mode, fetch
|
# requires device-mode, fetch
|
||||||
#
|
#
|
||||||
# use Telegram to chat with your Router and send commands
|
# use Telegram to chat with your Router and send commands
|
||||||
# https://rsc.eworm.de/doc/telegram-chat.md
|
# https://rsc.eworm.de/doc/telegram-chat.md
|
||||||
|
|
||||||
:local ExitOK false;
|
|
||||||
:onerror Err {
|
:onerror Err {
|
||||||
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
||||||
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
||||||
|
|
@ -48,8 +47,7 @@
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$WaitFullyConnected;
|
$WaitFullyConnected;
|
||||||
|
|
@ -63,8 +61,7 @@
|
||||||
|
|
||||||
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
|
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
|
||||||
$LogPrint warning $ScriptName ("Downloading required certificate failed.");
|
$LogPrint warning $ScriptName ("Downloading required certificate failed.");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$RandomDelay $TelegramRandomDelay;
|
$RandomDelay $TelegramRandomDelay;
|
||||||
|
|
@ -89,8 +86,7 @@
|
||||||
|
|
||||||
:if ($Data = false) do={
|
:if ($Data = false) do={
|
||||||
$LogPrint warning $ScriptName ("Failed getting updates.");
|
$LogPrint warning $ScriptName ("Failed getting updates.");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:local JSON [ :deserialize from=json value=$Data ];
|
:local JSON [ :deserialize from=json value=$Data ];
|
||||||
|
|
@ -146,8 +142,7 @@
|
||||||
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
|
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
|
||||||
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
|
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
|
||||||
$LogPrint error $ScriptName ("Failed creating directory!");
|
$LogPrint error $ScriptName ("Failed creating directory!");
|
||||||
:set ExitOK true;
|
:exit;
|
||||||
:error false;
|
|
||||||
}
|
}
|
||||||
$LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command);
|
$LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command);
|
||||||
:execute script=(":do {\n" . $Command . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \
|
:execute script=(":do {\n" . $Command . "\n} on-error={ /file/add name=\"" . $File . ".failed\" };" . \
|
||||||
|
|
@ -197,5 +192,5 @@
|
||||||
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
|
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
|
||||||
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
|
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
|
||||||
} do={
|
} do={
|
||||||
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
:global ExitError; $ExitError true [ :jobname ] $Err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue