mirror of
https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git
synced 2025-09-09 07:30:57 +02:00
little touch-up for telegram-bot-daemon.sh (#1306)
* little touch-up for telegram-bot-daemon.sh My bot sometimes receives a non-message json (spam I think) like this: {"ok":true,"result":[{"update_id":271754855, "channel_post":{"message_id":73,"chat" ...... in that case updateId has a value and chatId is empty so the markAsRead is never performed. In order to avoid that some non-message confusing the bot I propose insert an additional check. * Update telegram-bot-daemon.sh
This commit is contained in:
@@ -84,12 +84,17 @@ main() {
|
||||
messageAttr="message"
|
||||
messageVal=$(echo "$json" | $JQ -r '.result[0].message // ""')
|
||||
[ -z "$messageVal" ] && messageAttr="edited_message"
|
||||
|
||||
chatId=$(echo "$json" | $JQ -r ".result[0].$messageAttr.chat.id // \"\"")
|
||||
updateId=$(echo "$json" | $JQ -r '.result[0].update_id // ""')
|
||||
if [ "$updateId" != "" ] && [ -z "$chatId" ]; then
|
||||
markAsRead $updateId
|
||||
return 0
|
||||
fi;
|
||||
|
||||
[ -z "$chatId" ] && return 0 # no new messages
|
||||
|
||||
cmd=$(echo "$json" | $JQ -r ".result[0].$messageAttr.text // \"\"")
|
||||
updateId=$(echo "$json" | $JQ -r '.result[0].update_id // ""')
|
||||
|
||||
|
||||
if [ "$chatId" != "$userChatId" ]; then
|
||||
username=$(echo "$json" | $JQ -r ".result[0].$messageAttr.from.username // \"\"")
|
||||
|
Reference in New Issue
Block a user