bashbot: use Json2Array UPD for response also

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-15 19:26:04 +01:00
parent 277178389a
commit ef972c5714
1 changed files with 9 additions and 9 deletions

View File

@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
# 8 - curl/wget missing
# 10 - not bash!
#
#### $$VERSION$$ v1.30-dev-23-g0f27e71
#### $$VERSION$$ v1.30-dev-24-g2771783
##################################################################
# emmbeded system may claim bash but it is not
@ -555,21 +555,21 @@ sendJsonRetry(){
sendJsonResult(){
local offset=0
BOTSENT=( )
Json2Array 'UPD' <<<"$1"
[ -n "${BASHBOTDEBUG}" ] && log_message "New Result ==========\n$1"
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$1")"
BOTSENT[OK]="${UPD["ok"]}"
if [ "${BOTSENT[OK]}" = "true" ]; then
BOTSENT[RESULT]="$(JsonGetString '"result"' <<< "$1")"
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$1")"
BOTSENT[CHAT]="$(JsonGetValue '"result","chat","id"' <<< "$1")"
BOTSENT[ID]="${UPD["result","message_id"]}"
BOTSENT[CHAT]="${UPD["result","chat","id"]}"
[ -n "${UPD["result"]}" ] && BOTSENT[RESULT]="${UPD["result"]}"
return
# hot path everything OK!
else
# oops something went wrong!
if [ -n "$1" ]; then
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "$1")"
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "$1")"
grep -qs -F '"parameters","retry_after"' <<< "$1" &&\
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "$1")"
BOTSENT[ERROR]="${UPD["error_code"]}"
BOTSENT[DESCRIPTION]="${UPD["description"]}"
[ -n "${UPD["parameters","retry_after"]}" ] && BOTSENT[RETRY]="${UPD["parameters","retry_after"]}"
else
BOTSENT[OK]="false"
BOTSENT[ERROR]="999"