diff --git a/bashbot.sh b/bashbot.sh index 2222a02..81eaa57 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -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) diff --git a/modules/inline.sh b/modules/inline.sh index 2d8cc82..709e0f2 100644 --- a/modules/inline.sh +++ b/modules/inline.sh @@ -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"')")" } diff --git a/test/d-process_inline-test.sh b/test/d-process_inline-test.sh new file mode 100755 index 0000000..079c9c4 --- /dev/null +++ b/test/d-process_inline-test.sh @@ -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 diff --git a/test/d-process_inline-test/d-process_inline-test.input b/test/d-process_inline-test/d-process_inline-test.input new file mode 100644 index 0000000..c00e5a3 --- /dev/null +++ b/test/d-process_inline-test/d-process_inline-test.input @@ -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" + diff --git a/test/d-process_inline-test/d-process_inline-test.result b/test/d-process_inline-test/d-process_inline-test.result new file mode 100644 index 0000000..2922977 --- /dev/null +++ b/test/d-process_inline-test/d-process_inline-test.result @@ -0,0 +1,5 @@ +iQUERY: 0 message +iQUERY: FIRST_NAME Kay +iQUERY: LAST_NAME M +iQUERY: USER_ID 123456789 +iQUERY: USERNAME Gnadelwartz