From 4ebe2628b0819000fe359afbb7d17a883148eabd Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 28 Sep 2021 16:26:26 +0200 Subject: global-functions.d/notification-telegram: fix calculation on cut off --- global-functions.d/notification-telegram | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/global-functions.d/notification-telegram b/global-functions.d/notification-telegram index d8fe448..faf02d7 100644 --- a/global-functions.d/notification-telegram +++ b/global-functions.d/notification-telegram @@ -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" "" ]; -- cgit v1.2.3-54-g00ecf