global-functions.d/notification-telegram: subject in bold & underline

This makes the subject visually delimited.
This commit is contained in:
Christian Hesse 2021-07-09 16:50:08 +02:00
parent dc7fc0d385
commit 574c50908b
1 changed files with 11 additions and 10 deletions

View File

@ -77,7 +77,7 @@
:local Return $1;
:local Chars {
"body"={ "\\"; "`" };
"hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"plain"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
}
:foreach Char in=($Chars->$2) do={
@ -99,22 +99,23 @@
}
:local Truncated false;
:local Text ("*__" . [ $EscapeMD ("[" . $Identity . "] " . ($Notification->"subject")) "plain" ] . "__*\n\n");
:local LenSubject [ :len $Text ];
:local LenMessage [ :len ($Notification->"message") ];
:local LenLink [ :len ($Notification->"link") ];
:local Text ("[" . $Identity . "] " . ($Notification->"subject") . "\n\n" . ($Notification->"message"));
:local LenText [ :len $Text ];
:if ($LenText > (3968 - $LenLink)) do={
:set Text [ $EscapeMD ([ :pick $Text 0 (3840 - $LenLink) ] . "...") "body" ];
:if ($LenSubject + $LenMessage + $LenLink > 3968) do={
:set Text ($Text . [ $EscapeMD ([ :pick ($Notification->"message") 0 (3840 - $LenSubject - $LenLink) ] . "...") "body" ]);
:set Truncated true;
} else={
:set Text [ $EscapeMD $Text "body" ];
:set Text ($Text . [ $EscapeMD ($Notification->"message") "body" ]);
}
:if ($LenLink > 0) do={
:set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD ($Notification->"link") "hint" ]);
:set Text ($Text . "\n" . [ $SymbolForNotification "link" ] . [ $EscapeMD ($Notification->"link") "plain" ]);
}
: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) . "%!") "hint" ]);
(($LenText - [ :len $Text ]) * 100 / $LenText) . "%!") "plain" ]);
}
:set Text [ $UrlEncode $Text ];
:local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ];
@ -135,7 +136,7 @@
}
:set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \
[ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \
" " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]);
" " . [ / system clock get time ] . " and may be obsolete.") "plain" ]) ]);
:set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId;
parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") };
:if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={