From 77e05d4818041620ec1c5d70abd675bf25402b95 Mon Sep 17 00:00:00 2001 From: znanev <20048364+znanev@users.noreply.github.com> Date: Fri, 16 Aug 2019 11:28:11 +0100 Subject: [PATCH] Update telegram-bot-daemon.sh (#1124) Correctly handle situations where commands coming from group chats appear to be substrings of another command (for example /mem will not be matched, if command sent was /members). --- firmware_mod/scripts/telegram-bot-daemon.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/firmware_mod/scripts/telegram-bot-daemon.sh b/firmware_mod/scripts/telegram-bot-daemon.sh index 57a80da..956c500 100755 --- a/firmware_mod/scripts/telegram-bot-daemon.sh +++ b/firmware_mod/scripts/telegram-bot-daemon.sh @@ -42,15 +42,17 @@ imageAlerts() { } respond() { - case $1 in - /mem*) sendMem;; - /shot*) sendShot;; - /on*) detectionOn;; - /off*) detectionOff;; - /textalerts*) textAlerts;; - /imagealerts*) imageAlerts;; - /help*) $TELEGRAM m "######### Bot commands #########\n# /mem - show memory information\n# /shot - take a shot\n# /on - motion detect on\n# /off - motion detect off\n# /textalerts - Text alerts on motion detection\n# /imagealerts - Image alerts on motion detection";; - *) $TELEGRAM m "I can't respond to '$1' command" + cmd=$1 + [ $chatId -lt 0 ] && cmd=${1%%@*} + case $cmd in + /mem) sendMem;; + /shot) sendShot;; + /on) detectionOn;; + /off) detectionOff;; + /textalerts) textAlerts;; + /imagealerts) imageAlerts;; + /help | /start) $TELEGRAM m "######### Bot commands #########\n# /mem - show memory information\n# /shot - take a shot\n# /on - motion detect on\n# /off - motion detect off\n# /textalerts - Text alerts on motion detection\n# /imagealerts - Image alerts on motion detection";; + *) $TELEGRAM m "I can't respond to '$cmd' command" esac }