fix sendJsonResult and chat is not a number

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-12-18 14:47:53 +01:00
parent 53c7879c9f
commit 0db0215d9b
2 changed files with 7 additions and 6 deletions

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v1.2-dev2-36-g8b9cb1a #### $$VERSION$$ v1.2-dev2-37-g53c7879
# #
# Exit Codes: # Exit Codes:
# - 0 success (hopefully) # - 0 success (hopefully)
@ -442,7 +442,7 @@ sendJson(){
local json chat="" local json chat=""
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
chat='"chat_id":'"${1}"',' 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 fi
# compose final json # compose final json
json='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<"$2")"'}' 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_update "sendJson (curl) CHAT=${chat#*:} JSON=${2:0:100} URL=${3##*/}"
log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"${json}" 2>&1)" log_message "DEBUG sendJson ==========\n$("${JSONSHFILE}" -b -n <<<"${json}" 2>&1)"
fi fi
# not a number # chat id not a number
if [[ "${chat}" == *"NAN" ]]; then if [[ "${chat}" == *"NAN\"," ]]; then
sendJsonResult "$(printf '["ok"]\tfalse\n["error_code"]\t400\n["description"]\t"Bad Request: chat id not a number"\n')"\ sendJsonResult "$(printf '["ok"]\tfalse\n["error_code"]\t400\n["description"]\t"Bad Request: chat id not a number"\n')"\
"sendJson (NAN)" "$@" "sendJson (NAN)" "$@"
return
fi fi
# OK here we go ... # OK here we go ...
# route to curl/wget specific function # route to curl/wget specific function
@ -567,7 +568,7 @@ sendJsonResult(){
# hot path everything OK! # hot path everything OK!
else else
# oops something went wrong! # oops something went wrong!
if [ "${res}" != "" ]; then if [ "${1}" != "" ]; then
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")" BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")"
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")" BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")"
grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\ grep -qs -F '"parameters","retry_after"' <<< "${1}" &&\

View File

@ -183,5 +183,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md) #### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v1.2-dev2-36-g8b9cb1a #### $$VERSION$$ v1.2-dev2-37-g53c7879