global-functions.d/notification-telegram: fix calculation on cut off

This commit is contained in:
Christian Hesse 2021-09-28 16:26:26 +02:00
parent 72d50aa13f
commit 4ebe2628b0
1 changed files with 3 additions and 2 deletions

View File

@ -103,7 +103,8 @@
:local LenSubject [ :len $Text ];
:local LenMessage [ :len ($Notification->"message") ];
:local LenLink [ :len ($Notification->"link") ];
:if ($LenSubject + $LenMessage + $LenLink > 3968) do={
:local LenSum ($LenSubject + $LenMessage + $LenLink);
:if ($LenSum > 3968) do={
:set Text ($Text . [ $EscapeMD ([ :pick ($Notification->"message") 0 (3840 - $LenSubject - $LenLink) ] . "...") "body" ]);
:set Truncated true;
} else={
@ -115,7 +116,7 @@
:if ($Truncated = true) do={
:set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \
[ $EscapeMD ("The Telegram message was too long and has been truncated, cut off " . \
(($LenText - [ :len $Text ]) * 100 / $LenText) . "%!") "plain" ]);
(($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%!") "plain" ]);
}
:set Text [ $UrlEncode $Text ];
:local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ];