sms-forward: switch to $LogPrint

This commit is contained in:
Christian Hesse 2024-03-08 12:45:38 +01:00
parent 5a487d15c2
commit be1aeccbe5

View file

@ -19,7 +19,7 @@
:global SmsForwardHooks; :global SmsForwardHooks;
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrint;
:global LogPrintOnce; :global LogPrintOnce;
:global ScriptLock; :global ScriptLock;
:global SendNotification2; :global SendNotification2;
@ -41,7 +41,7 @@
:local Settings [ /tool/sms/get ]; :local Settings [ /tool/sms/get ];
:if ([ /interface/lte/get ($Settings->"port") running ] != true) do={ :if ([ /interface/lte/get ($Settings->"port") running ] != true) do={
$LogPrintExit2 info $ScriptName ("The LTE interface is not in running state, skipping.") false; $LogPrint info $ScriptName ("The LTE interface is not in running state, skipping.");
:error true; :error true;
} }
@ -56,7 +56,7 @@
:if ($Phone = $Settings->"allowed-number" && \ :if ($Phone = $Settings->"allowed-number" && \
($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={ ($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={
$LogPrintExit2 debug $ScriptName ("Removing SMS, which started a script.") false; $LogPrint debug $ScriptName ("Removing SMS, which started a script.");
/tool/sms/inbox/remove $Sms; /tool/sms/inbox/remove $Sms;
} else={ } else={
:set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \ :set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \
@ -64,20 +64,16 @@
:foreach Hook in=$SmsForwardHooks do={ :foreach Hook in=$SmsForwardHooks do={
:if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={ :if ($Phone~($Hook->"allowed-number") && ($SmsVal->"message")~($Hook->"match")) do={
:if ([ $ValidateSyntax ($Hook->"command") ] = true) do={ :if ([ $ValidateSyntax ($Hook->"command") ] = true) do={
$LogPrintExit2 info $ScriptName ("Running hook '" . $Hook->"match" . "': " . \ $LogPrint info $ScriptName ("Running hook '" . $Hook->"match" . "': " . $Hook->"command");
$Hook->"command") false;
:do { :do {
:local Command [ :parse ($Hook->"command") ]; :local Command [ :parse ($Hook->"command") ];
$Command Phone=$Phone Message=($SmsVal->"message"); $Command Phone=$Phone Message=($SmsVal->"message");
:set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . \ :set Messages ($Messages . "\n\nRan hook '" . $Hook->"match" . "':\n" . $Hook->"command");
$Hook->"command");
} on-error={ } on-error={
$LogPrintExit2 warning $ScriptName ("The code for hook '" . $Hook->"match" . \ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed to run!");
"' failed to run!") false;
} }
} else={ } else={
$LogPrintExit2 warning $ScriptName ("The code for hook '" . $Hook->"match" . \ $LogPrint warning $ScriptName ("The code for hook '" . $Hook->"match" . "' failed syntax validation!");
"' failed syntax validation!") false;
} }
} }
} }