mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-15 04:24:29 +02:00
mod/notification-matrix: switch to $LogPrint
This commit is contained in:
parent
9b8d3f7970
commit
279993e965
1 changed files with 23 additions and 18 deletions
|
@ -20,10 +20,10 @@
|
||||||
:global MatrixQueue;
|
:global MatrixQueue;
|
||||||
|
|
||||||
:global IsFullyConnected;
|
:global IsFullyConnected;
|
||||||
:global LogPrintExit2;
|
:global LogPrint;
|
||||||
|
|
||||||
:if ([ $IsFullyConnected ] = false) do={
|
:if ([ $IsFullyConnected ] = false) do={
|
||||||
$LogPrintExit2 debug $0 ("System is not fully connected, not flushing.") false;
|
$LogPrint debug $0 ("System is not fully connected, not flushing.");
|
||||||
:return false;
|
:return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
:local QueueLen [ :len $MatrixQueue ];
|
:local QueueLen [ :len $MatrixQueue ];
|
||||||
|
|
||||||
:if ([ :len [ /system/scheduler/find where name="_FlushMatrixQueue" ] ] > 0 && $QueueLen = 0) do={
|
:if ([ :len [ /system/scheduler/find where name="_FlushMatrixQueue" ] ] > 0 && $QueueLen = 0) do={
|
||||||
$LogPrintExit2 warning $0 ("Flushing Matrix messages from scheduler, but queue is empty.") false;
|
$LogPrint warning $0 ("Flushing Matrix messages from scheduler, but queue is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
:foreach Id,Message in=$MatrixQueue do={
|
:foreach Id,Message in=$MatrixQueue do={
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
$Message->"formatted" . "\" }") as-value;
|
$Message->"formatted" . "\" }") as-value;
|
||||||
:set ($MatrixQueue->$Id);
|
:set ($MatrixQueue->$Id);
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 debug $0 ("Sending queued Matrix message failed.") false;
|
$LogPrint debug $0 ("Sending queued Matrix message failed.");
|
||||||
:set AllDone false;
|
:set AllDone false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
:global MatrixRoomOverride;
|
:global MatrixRoomOverride;
|
||||||
|
|
||||||
:global EitherOr;
|
:global EitherOr;
|
||||||
:global LogPrintExit2;
|
:global LogPrint;
|
||||||
:global SymbolForNotification;
|
:global SymbolForNotification;
|
||||||
|
|
||||||
:local PrepareText do={
|
:local PrepareText do={
|
||||||
|
@ -134,7 +134,7 @@
|
||||||
"\"format\": \"org.matrix.custom.html\", \"formatted_body\": \"" . \
|
"\"format\": \"org.matrix.custom.html\", \"formatted_body\": \"" . \
|
||||||
$Formatted . "\" }") as-value;
|
$Formatted . "\" }") as-value;
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 info $0 ("Failed sending Matrix notification! Queuing...") false;
|
$LogPrint info $0 ("Failed sending Matrix notification! Queuing...");
|
||||||
|
|
||||||
:if ([ :typeof $MatrixQueue ] = "nothing") do={
|
:if ([ :typeof $MatrixQueue ] = "nothing") do={
|
||||||
:set MatrixQueue ({});
|
:set MatrixQueue ({});
|
||||||
|
@ -184,7 +184,7 @@
|
||||||
:local Pass [ :tostr $2 ];
|
:local Pass [ :tostr $2 ];
|
||||||
|
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
:global LogPrintExit2;
|
:global LogPrint;
|
||||||
:global ParseJson;
|
:global ParseJson;
|
||||||
|
|
||||||
:global MatrixAccessToken;
|
:global MatrixAccessToken;
|
||||||
|
@ -195,9 +195,10 @@
|
||||||
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
|
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
|
||||||
("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data");
|
("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data");
|
||||||
:set MatrixHomeServer ([ $ParseJson ([ $ParseJson [ $CharacterReplace $Data " " "" ] ]->"m.homeserver") ]->"base_url");
|
:set MatrixHomeServer ([ $ParseJson ([ $ParseJson [ $CharacterReplace $Data " " "" ] ]->"m.homeserver") ]->"base_url");
|
||||||
$LogPrintExit2 debug $0 ("Home server is: " . $MatrixHomeServer) false;
|
$LogPrint debug $0 ("Home server is: " . $MatrixHomeServer);
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 error $0 ("Failed getting home server!") true;
|
$LogPrint error $0 ("Failed getting home server!");
|
||||||
|
:error false;
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ([ :pick $MatrixHomeServer 0 8 ] = "https://") do={
|
:if ([ :pick $MatrixHomeServer 0 8 ] = "https://") do={
|
||||||
|
@ -209,18 +210,20 @@
|
||||||
http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \
|
http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \
|
||||||
("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data");
|
("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data");
|
||||||
:set MatrixAccessToken ([ $ParseJson $Data ]->"access_token");
|
:set MatrixAccessToken ([ $ParseJson $Data ]->"access_token");
|
||||||
$LogPrintExit2 debug $0 ("Access token is: " . $MatrixAccessToken) false;
|
$LogPrint debug $0 ("Access token is: " . $MatrixAccessToken);
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 error $0 ("Failed logging in (and getting access token)!") true;
|
$LogPrint error $0 ("Failed logging in (and getting access token)!");
|
||||||
|
:error false;
|
||||||
}
|
}
|
||||||
|
|
||||||
:do {
|
:do {
|
||||||
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
|
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
|
||||||
":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \
|
":global MatrixHomeServer \"" . $MatrixHomeServer . "\";\n" . \
|
||||||
":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n");
|
":global MatrixAccessToken \"" . $MatrixAccessToken . "\";\n");
|
||||||
$LogPrintExit2 info $0 ("Appended configuration to global-config-overlay. Now create and join a room, please!") false;
|
$LogPrint info $0 ("Appended configuration to global-config-overlay. Now create and join a room, please!");
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 error $0 ("Failed appending configuration to global-config-overlay!") true;
|
$LogPrint error $0 ("Failed appending configuration to global-config-overlay!");
|
||||||
|
:error false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +231,7 @@
|
||||||
:set SetupMatrixJoinRoom do={
|
:set SetupMatrixJoinRoom do={
|
||||||
:global MatrixRoom [ :tostr $1 ];
|
:global MatrixRoom [ :tostr $1 ];
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrint;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
|
|
||||||
:global MatrixAccessToken;
|
:global MatrixAccessToken;
|
||||||
|
@ -240,16 +243,18 @@
|
||||||
http-method=post http-data="" \
|
http-method=post http-data="" \
|
||||||
("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \
|
("https://" . $MatrixHomeServer . "/_matrix/client/r0/rooms/" . [ $UrlEncode $MatrixRoom ] . \
|
||||||
"/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value;
|
"/join?access_token=" . [ $UrlEncode $MatrixAccessToken ]) as-value;
|
||||||
$LogPrintExit2 debug $0 ("Joined the room.") false;
|
$LogPrint debug $0 ("Joined the room.");
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 error $0 ("Failed joining the room!") true;
|
$LogPrint error $0 ("Failed joining the room!");
|
||||||
|
:error false;
|
||||||
}
|
}
|
||||||
|
|
||||||
:do {
|
:do {
|
||||||
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
|
/system/script/set global-config-overlay source=([ get global-config-overlay source ] . "\n" . \
|
||||||
":global MatrixRoom \"" . $MatrixRoom . "\";\n");
|
":global MatrixRoom \"" . $MatrixRoom . "\";\n");
|
||||||
$LogPrintExit2 info $0 ("Appended configuration to global-config-overlay. Please review and cleanup!") false;
|
$LogPrint info $0 ("Appended configuration to global-config-overlay. Please review and cleanup!");
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 error $0 ("Failed appending configuration to global-config-overlay!") true;
|
$LogPrint error $0 ("Failed appending configuration to global-config-overlay!");
|
||||||
|
:error false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue