aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-10-14 21:53:11 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-10-14 22:07:02 +0200
commitc40c792806df3385f64905f7d989bb08c884d916 (patch)
tree1c4ec78a9134d487f6eccab576e94d93c6ede266
parent0009c7fc656726af809b0015622d226467a5dbf7 (diff)
global-functions: $SendTelegram: clean up
-rw-r--r--global-functions30
1 files changed, 19 insertions, 11 deletions
diff --git a/global-functions b/global-functions
index 3ffe737..2dafe4b 100644
--- a/global-functions
+++ b/global-functions
@@ -774,14 +774,26 @@
:local EscapeMD do={
:global TelegramFixedWidthFont;
+ :global CharacterReplace;
+
:if ($TelegramFixedWidthFont != true) do={
:return $1;
}
:local Return $1;
- :foreach Char in={ "."; "!" } do={
+ :local Chars {
+ "fixed"={ "\\"; "`" };
+ "hint"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
+ "#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
+ }
+ :foreach Char in=($Chars->$2) do={
:set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ];
}
+
+ :if ($2 = "fixed") do={
+ :return ("```\n" . $Return . "\n```");
+ }
+
:return $Return;
}
@@ -795,19 +807,15 @@
}
:local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message);
- :local ParseMode;
- :if ($TelegramFixedWidthFont = true) do={
- :set Text ("```\n" . [ $CharacterReplace [ $CharacterReplace $Text \
- ("\\") ("\\\\") ] ("`") ("\\`") ] . "\n```");
- :set ParseMode "MarkdownV2";
- }
:if ([ :len $Text ] > 3968) do={
- :set Text ([ :pick $Text 0 3840 ] . "..." . \
- [ $IfThenElse ($TelegramFixedWidthFont = true) ("\n```") "" ] . \
+ :set Text ([ $EscapeMD ([ :pick $Text 0 3840 ] . "...") "fixed" ] . \
"\n\n" . [ $SymbolForNotification "scissors" ] . \
- [ $EscapeMD "The Telegram message was too long and has been truncated!" ]);
+ [ $EscapeMD "The Telegram message was too long and has been truncated!" "hint" ]);
+ } else={
+ :set Text [ $EscapeMD $Text "fixed" ];
}
:set Text [ $UrlEncode $Text ];
+ :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ];
:do {
:if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={
@@ -825,7 +833,7 @@
}
:set Text ($Text . [ $UrlEncode ("\n\n" . [ $SymbolForNotification "alarm-clock" ] . \
[ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \
- " " . [ / system clock get time ] . " and may be obsolete.") ]) ]);
+ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]);
:set ($TelegramQueue->[ :len $TelegramQueue ]) {
chatid=$ChatId; parsemode=$ParseMode; text=$Text; silent=$Silent };
:if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={