From 0db0215d9b7cd1fe8683c0d1d6225c82b819abc3 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 18 Dec 2020 14:47:53 +0100 Subject: [PATCH] fix sendJsonResult and chat is not a number --- bashbot.sh | 11 ++++++----- doc/0_install.md | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index abcdc61..dfa5ff6 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.2-dev2-36-g8b9cb1a +#### $$VERSION$$ v1.2-dev2-37-g53c7879 # # Exit Codes: # - 0 success (hopefully) @@ -442,7 +442,7 @@ sendJson(){ local json chat="" if [ -n "${1}" ]; then chat='"chat_id":'"${1}"',' - [[ "${1}" == *[!0-9-]* ]] && chat="${chat} NAN" # chat id not a number! + [[ "${1}" == *[!0-9-]* ]] && chat='"chat_id":"'"${1}"' NAN",' # chat id not a number! fi # compose final json json='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<"$2")"'}' @@ -450,10 +450,11 @@ sendJson(){ log_update "sendJson (curl) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}" log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"${json}" 2>&1)" fi - # not a number - if [[ "${chat}" == *"NAN" ]]; then + # chat id not a number + if [[ "${chat}" == *"NAN\"," ]]; then sendJsonResult "$(printf '["ok"]\tfalse\n["error_code"]\t400\n["description"]\t"Bad Request: chat id not a number"\n')"\ "sendJson (NAN)" "$@" + return fi # OK here we go ... # route to curl/wget specific function @@ -567,7 +568,7 @@ sendJsonResult(){ # hot path everything OK! else # oops something went wrong! - if [ "${res}" != "" ]; then + if [ "${1}" != "" ]; then BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")" BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")" grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\ diff --git a/doc/0_install.md b/doc/0_install.md index 62f6754..41d4cf4 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -183,5 +183,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v1.2-dev2-36-g8b9cb1a +#### $$VERSION$$ v1.2-dev2-37-g53c7879