telegram-chat: reply with a hint when untrusted...

... but only when activating via identity.
This commit is contained in:
Christian Hesse 2023-02-02 09:48:43 +01:00
parent 08383daa5c
commit b794d98cbb

View file

@ -79,6 +79,7 @@ $WaitFullyConnected;
:local FromID [ $JsonGetKey $From "id" ]; :local FromID [ $JsonGetKey $From "id" ];
:local FromUserName [ $JsonGetKey $From "username" ]; :local FromUserName [ $JsonGetKey $From "username" ];
:local ChatID [ $JsonGetKey [ $JsonGetKey $Message "chat" ] "id" ]; :local ChatID [ $JsonGetKey [ $JsonGetKey $Message "chat" ] "id" ];
:local Text [ $JsonGetKey $Message "text" ];
:foreach IdsTrusted in=($TelegramChatId, $TelegramChatIdsTrusted) do={ :foreach IdsTrusted in=($TelegramChatId, $TelegramChatIdsTrusted) do={
:if ($FromID = $IdsTrusted || $FromUserName = $IdsTrusted) do={ :if ($FromID = $IdsTrusted || $FromUserName = $IdsTrusted) do={
:set Trusted true; :set Trusted true;
@ -86,7 +87,6 @@ $WaitFullyConnected;
} }
:if ($Trusted = true) do={ :if ($Trusted = true) do={
:local Text [ $JsonGetKey $Message "text" ];
:if ([ :pick $Text 0 1 ] = "!") do={ :if ([ :pick $Text 0 1 ] = "!") do={
:if ($Text ~ ("^! *(" . [ $EscapeForRegEx $Identity ] . "|@" . $TelegramChatGroups . ")\$")) do={ :if ($Text ~ ("^! *(" . [ $EscapeForRegEx $Identity ] . "|@" . $TelegramChatGroups . ")\$")) do={
:set TelegramChatActive true; :set TelegramChatActive true;
@ -124,6 +124,11 @@ $WaitFullyConnected;
} }
} else={ } else={
$LogPrintExit2 warning $0 ("Received a message from untrusted contact '" . $FromUserName . "' (ID " . $FromID . ")!") false; $LogPrintExit2 warning $0 ("Received a message from untrusted contact '" . $FromUserName . "' (ID " . $FromID . ")!") false;
:if ($Text ~ ("^! *" . [ $EscapeForRegEx $Identity ] . "\$")) do={
$SendTelegram2 ({ origin=$0; chatid=$ChatID; silent=false; \
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
message=("You are not trusted.") });
}
} }
} }
} }