mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
fix iQUERY[0]
This commit is contained in:
parent
82eb3c7b04
commit
5b8f2a2118
@ -12,7 +12,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-dev-3-g9bcab66
|
||||
#### $$VERSION$$ v0.70-5-g82eb3c7
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-dev-3-g9bcab66
|
||||
#### $$VERSION$$ v0.70-5-g82eb3c7
|
||||
|
||||
# source from commands.sh to use the inline functions
|
||||
|
||||
@ -14,12 +14,13 @@ declare -A iQUERY
|
||||
export iQUERY
|
||||
|
||||
process_inline() {
|
||||
echo "$UPDATE" >>INLINE.log
|
||||
iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"$PROCESS_NUMBER"',"inline_query","query"')")"
|
||||
iQUERY[USER_ID]="$(JsonGetString <<<"${UPDATE}" '"result",'"$PROCESS_NUMBER"',"inline_query","from","id"')"
|
||||
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"$PROCESS_NUMBER"',"inline_query","from","first_name"')")"
|
||||
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"$PROCESS_NUMBER"',"inline_query","from","last_name"')")"
|
||||
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"$PROCESS_NUMBER"',"inline_query","from","username"')")"
|
||||
set -x
|
||||
local num="${1}"
|
||||
iQUERY[0]="$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')"
|
||||
iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')"
|
||||
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")"
|
||||
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")"
|
||||
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")"
|
||||
}
|
||||
|
||||
|
||||
|
42
test/d-process_inline-test.sh
Executable file
42
test/d-process_inline-test.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-5-g82eb3c7
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
source "./ALL-tests.inc.sh"
|
||||
|
||||
set -e
|
||||
|
||||
# source bashbot.sh functionw
|
||||
cd "${TESTDIR}" || exit 1
|
||||
# shellcheck source=./bashbot.sh
|
||||
source "${TESTDIR}/bashbot.sh" source
|
||||
# shellcheck source=./bashbot.sh
|
||||
source "${TESTDIR}/modules/inline.sh" source
|
||||
|
||||
# overwrite get_file for test
|
||||
get_file() {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
# get telegram input from file
|
||||
export UPDATE
|
||||
UPDATE="$(cat "${INPUTFILE}")"
|
||||
|
||||
# run process_message with and without phyton
|
||||
echo "Check process_inline ..."
|
||||
for i in 1 2
|
||||
do
|
||||
[ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue
|
||||
[ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE
|
||||
[ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes"
|
||||
set -x
|
||||
{ process_inline "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
|
||||
# output processed input
|
||||
print_array "iQUERY" >"${OUTPUTFILE}"
|
||||
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||
echo "${SUCCESS}"
|
||||
done
|
||||
|
||||
cd "${DIRME}" || exit 1
|
11
test/d-process_inline-test/d-process_inline-test.input
Normal file
11
test/d-process_inline-test/d-process_inline-test.input
Normal file
@ -0,0 +1,11 @@
|
||||
["ok"] true
|
||||
["result",0,"update_id"]i 1234567890
|
||||
["result",0,"inline_query","id"] "987654321"
|
||||
["result",0,"inline_query","query"] "message"
|
||||
["result",0,"inline_query","from","id"] 123456789
|
||||
["result",0,"inline_query","from","is_bot"] false
|
||||
["result",0,"inline_query","from","first_name"] "Kay"
|
||||
["result",0,"inline_query","from","last_name"] "M"
|
||||
["result",0,"inline_query","from","username"] "Gnadelwartz"
|
||||
["result",0,"inline_query","from","language_code"] "de"
|
||||
|
5
test/d-process_inline-test/d-process_inline-test.result
Normal file
5
test/d-process_inline-test/d-process_inline-test.result
Normal file
@ -0,0 +1,5 @@
|
||||
iQUERY: 0 message
|
||||
iQUERY: FIRST_NAME Kay
|
||||
iQUERY: LAST_NAME M
|
||||
iQUERY: USER_ID 123456789
|
||||
iQUERY: USERNAME Gnadelwartz
|
Loading…
Reference in New Issue
Block a user