bin: process_updates: use process_multi for preprocessing

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-02-18 18:59:27 +01:00
parent 882efa8f1a
commit 8b18f25c88
2 changed files with 11 additions and 11 deletions

View File

@ -15,12 +15,12 @@ USAGE='process_update.sh [-h|--help] [debug] [<file]'
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 30.01.2021 19:14
#
#### $$VERSION$$ v1.45-dev-30-g8efbfca
#### $$VERSION$$ v1.45-dev-38-g882efa8
#===============================================================================
####
# parse args
COMMAND="process_update"
COMMAND="process_multi_updates"
# set bashbot environment
source "${0%/*}/bashbot_env.inc.sh" "debug" # debug
@ -34,12 +34,6 @@ print_help "${1:-nix}"
json='{"result": ['"$(cat)"']}'
UPDATE="$(${JSONSHFILE} -b -n <<<"${json}" 2>/dev/null)"
# escape bash $ expansion bug
UPDATE="${UPDATE//$/\\$}"
# assign to bashbot ARRAY
Json2Array 'UPD' <<<"${UPDATE}"
# process telegram update
"${COMMAND}" "0" "$1"
"${COMMAND}" "$1"

View File

@ -4,7 +4,7 @@
# File: processUpdates.sh
# Note: DO NOT EDIT! this file will be overwritten on update
#
#### $$VERSION$$ v1.45-dev-30-g8efbfca
#### $$VERSION$$ v1.45-dev-38-g882efa8
##################################################################
##############
@ -43,18 +43,24 @@ delete_webhook() {
}
################
# processing of updates starts here
# processing of array of updates starts here
process_multi_updates() {
local max num debug="$1"
# get num array elements
max="$(grep -F ',"update_id"]' <<< "${UPDATE}" | tail -1 | cut -d , -f 2 )"
# escape bash $ expansion bug
UPDATE="${UPDATE//$/\\$}"
# convert updates to bash array
Json2Array 'UPD' <<<"${UPDATE}"
# iterate over array
for ((num=0; num<=max; num++)); do
process_update "${num}" "${debug}"
done
}
################
# processing of a single array item of update
# $1 array index
process_update() {
local num="$1" debug="$2"
pre_process_message "${num}"