aboutsummaryrefslogtreecommitdiffstats
path: root/mod/notification-telegram.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'mod/notification-telegram.rsc')
-rw-r--r--mod/notification-telegram.rsc29
1 files changed, 17 insertions, 12 deletions
diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc
index 745367a..9a628ce 100644
--- a/mod/notification-telegram.rsc
+++ b/mod/notification-telegram.rsc
@@ -81,24 +81,29 @@
:global UrlEncode;
:local EscapeMD do={
+ :local Text [ :tostr $1 ];
+ :local Mode [ :tostr $2 ];
+ :local Excl [ :tostr $3 ];
+
:global CharacterReplace;
:global IfThenElse;
- :local Return $1;
:local Chars {
- "body"={ "\\"; "`" };
+ "body"={ "\\"; "`" };
"plain"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
"#"; "+"; "-"; "="; "|"; "{"; "}"; "."; "!" };
}
- :foreach Char in=($Chars->$2) do={
- :set Return [ $CharacterReplace $Return $Char ("\\" . $Char) ];
+ :foreach Char in=($Chars->$Mode) do={
+ :if ([ :typeof [ :find $Excl $Char ] ] = "nil") do={
+ :set Text [ $CharacterReplace $Text $Char ("\\" . $Char) ];
+ }
}
- :if ($2 = "body") do={
- :return ("```\n" . $Return . "\n```");
+ :if ($Mode = "body") do={
+ :return ("```\n" . $Text . "\n```");
}
- :return $Return;
+ :return $Text;
}
:local ChatId [ $EitherOr ($Notification->"chatid") \
@@ -133,8 +138,8 @@
}
:if ($Truncated = true) do={
:set Text ($Text . "\n" . [ $SymbolForNotification "scissors" ] . \
- [ $EscapeMD ("The message was too long and has been truncated, cut off " . \
- (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%!") "plain" ]);
+ [ $EscapeMD ("The message was too long and has been truncated, cut off _" . \
+ (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%_!") "plain" "_" ]);
}
:do {
@@ -149,14 +154,14 @@
"&parse_mode=MarkdownV2&text=" . [ $UrlEncode $Text ]) as-value ]->"data");
:set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1;
} on-error={
- $LogPrint info $0 ("Failed sending telegram notification! Queuing...");
+ $LogPrint info $0 ("Failed sending Telegram notification! Queuing...");
:if ([ :typeof $TelegramQueue ] = "nothing") do={
:set TelegramQueue ({});
}
:set Text ($Text . "\n" . [ $SymbolForNotification "alarm-clock" ] . \
- [ $EscapeMD ("This message was queued since " . [ /system/clock/get date ] . \
- " " . [ /system/clock/get time ] . " and may be obsolete.") "plain" ]);
+ [ $EscapeMD ("This message was queued since _" . [ /system/clock/get date ] . \
+ " " . [ /system/clock/get time ] . "_ and may be obsolete.") "plain" "_" ]);
:set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId;
text=$Text; silent=($Notification->"silent"); replyto=($Notification->"replyto") };
:if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] = 0) do={