mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-29 10:43:53 +00:00
fix errors in JsonGet found by testsuite
This commit is contained in:
parent
48e6f64d58
commit
fbd86c3412
29
bashbot.sh
29
bashbot.sh
@ -10,7 +10,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$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -391,7 +391,7 @@ remove_keyboard() {
|
|||||||
|
|
||||||
get_file() {
|
get_file() {
|
||||||
[ "$1" = "" ] && return
|
[ "$1" = "" ] && return
|
||||||
echo "$FILE_URL$(curl -s "$GET_URL" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)"
|
echo "${FILE_URL}$(curl -s "${GET_URL}" -F "file_id=$1" | ./JSON.sh/JSON.sh -s | grep '\["result","file_path"\]' | cut -f 2 | cut -d '"' -f 2)"
|
||||||
}
|
}
|
||||||
|
|
||||||
send_file() {
|
send_file() {
|
||||||
@ -519,18 +519,19 @@ process_client() {
|
|||||||
process_message "$PROCESS_NUMBER"
|
process_message "$PROCESS_NUMBER"
|
||||||
# Tmux
|
# Tmux
|
||||||
copname="$ME"_"${CHAT[ID]}"
|
copname="$ME"_"${CHAT[ID]}"
|
||||||
|
|
||||||
source commands.sh
|
source commands.sh
|
||||||
|
|
||||||
tmpcount="COUNT${CHAT[ID]}"
|
tmpcount="COUNT${CHAT[ID]}"
|
||||||
grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>${COUNTFILE}
|
grep -q "$tmpcount" <"${COUNTFILE}" >/dev/null 2>&1 || echo "$tmpcount">>${COUNTFILE}
|
||||||
# To get user count execute bash bashbot.sh count
|
# To get user count execute bash bashbot.sh count
|
||||||
}
|
}
|
||||||
JsonGetString() {
|
JsonGetString() {
|
||||||
sed -n -e '/\['"$1"'\]/ s/.*\][ \t]"\(.*\)"$/\1/p'
|
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]"\(.*\)"$/\1/p'
|
||||||
|
}
|
||||||
|
JsonGetLine() {
|
||||||
|
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\]\][ \t]//p'
|
||||||
}
|
}
|
||||||
JsonGetValue() {
|
JsonGetValue() {
|
||||||
sed -n -e '/\['"$1"'\]/ s/.*\][ \t]//p'
|
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p'
|
||||||
}
|
}
|
||||||
process_message() {
|
process_message() {
|
||||||
local num="$1"
|
local num="$1"
|
||||||
@ -575,17 +576,17 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
URLS[AUDIO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","audio","file_id"' <"$TMP")")")"
|
URLS[AUDIO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","audio","file_id"' <"$TMP")")"
|
||||||
# Document
|
# Document
|
||||||
URLS[DOCUMENT]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")")"
|
URLS[DOCUMENT]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")"
|
||||||
# Photo
|
# Photo
|
||||||
URLS[PHOTO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","photo",0,"file_id"' <"$TMP")")")"
|
URLS[PHOTO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","photo",0,"file_id"' <"$TMP")")"
|
||||||
# Sticker
|
# Sticker
|
||||||
URLS[STICKER]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")")"
|
URLS[STICKER]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")"
|
||||||
# Video
|
# Video
|
||||||
URLS[VIDEO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","video","file_id"' <"$TMP")")")"
|
URLS[VIDEO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","video","file_id"' <"$TMP")")"
|
||||||
# Voice
|
# Voice
|
||||||
URLS[VOICE]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","voice","file_id"' <"$TMP")")")"
|
URLS[VOICE]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","voice","file_id"' <"$TMP")")"
|
||||||
|
|
||||||
# Contact
|
# Contact
|
||||||
CONTACT[NUMBER]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")")"
|
CONTACT[NUMBER]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")")"
|
||||||
@ -600,7 +601,7 @@ process_message() {
|
|||||||
LOCATION[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","longitude"' <"$TMP")"
|
LOCATION[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","longitude"' <"$TMP")"
|
||||||
LOCATION[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","latitude"' <"$TMP")"
|
LOCATION[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","latitude"' <"$TMP")"
|
||||||
NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')"
|
NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')"
|
||||||
#rm "$TMP"
|
rm "$TMP"
|
||||||
}
|
}
|
||||||
# get bot name
|
# get bot name
|
||||||
getBotName() {
|
getBotName() {
|
||||||
@ -619,7 +620,7 @@ if [ "$ME" = "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback
|
# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback
|
||||||
if which python >/dev/null 2>&1 || which phyton2 >/dev/null 2>&1; then
|
if [ "${BASHDECODE}" != "yes" ] && which python >/dev/null 2>&1 ; then
|
||||||
JsonDecode() {
|
JsonDecode() {
|
||||||
printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))'
|
printf '"%s\\n"' "${1//\"/\\\"}" | python -c 'import json, sys; sys.stdout.write(json.load(sys.stdin).encode("utf-8"))'
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
# common variables
|
# common variables
|
||||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# and every time we create new hooks
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
@ -19,7 +19,7 @@ tests=0
|
|||||||
passed=0
|
passed=0
|
||||||
#all_tests=${__dirname:}
|
#all_tests=${__dirname:}
|
||||||
#echo PLAN ${#all_tests}
|
#echo PLAN ${#all_tests}
|
||||||
for test in $(find ./*-test.sh | sort -u) ;
|
for test in $(find ./${pass}*-test.sh | sort -u) ;
|
||||||
do
|
do
|
||||||
[ "${test}" = "test/all-tests.sh" ] && continue
|
[ "${test}" = "test/all-tests.sh" ] && continue
|
||||||
[ ! -x "${test}" ] && continue
|
[ ! -x "${test}" ] && continue
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
../dev/hooks/pre-commit.sh
|
../dev/hooks/pre-commit.sh
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
../dev/hooks/pre-push.sh
|
../dev/hooks/pre-push.sh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
#### $$VERSION$$ 0.70-dev-23-g48e6f64
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -21,13 +21,20 @@ get_file() {
|
|||||||
export UPDATE
|
export UPDATE
|
||||||
UPDATE="$(cat "${INPUTFILE}")"
|
UPDATE="$(cat "${INPUTFILE}")"
|
||||||
|
|
||||||
set -x
|
# run process_message with and without phyton
|
||||||
process_message "0" >>"${LOGFILE}" 2>&1; set +x
|
echo "Check process_message ..."
|
||||||
|
for i in 1 2
|
||||||
|
do
|
||||||
|
[ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue
|
||||||
|
[ "${i}" = "1" ] && echo " ... JsonDecode Phyton"
|
||||||
|
[ "${i}" = "2" ] && echo " ... JsonDecode Bash" && export BASHDECODE="yes"
|
||||||
|
set -x
|
||||||
|
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||||
|
|
||||||
|
# output processed input
|
||||||
|
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}"
|
||||||
|
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||||
|
echo "${SUCCESS}"
|
||||||
|
done
|
||||||
|
|
||||||
cd "${DIRME}" || exit 1
|
cd "${DIRME}" || exit 1
|
||||||
|
|
||||||
# output processed input
|
|
||||||
echo "Diff process_message input and output ..."
|
|
||||||
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}"
|
|
||||||
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
|
||||||
|
|
||||||
echo "${SUCCESS}"
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
["ok"] true
|
["ok"] true
|
||||||
["result",0,"update_id"] 146860800
|
["result",0,"update_id"] 146860800
|
||||||
["result",0,"message","message_id"] 6541
|
["result",0,"message","message_id"] 6541 6541 # this is a cross check for JsonGetValue
|
||||||
|
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
||||||
|
["result",0,"message","text"] "Cross check, this second text must be ignored"
|
||||||
["result",0,"message","from","id"] 123456789
|
["result",0,"message","from","id"] 123456789
|
||||||
["result",0,"message","from","is_bot"] false
|
["result",0,"message","from","is_bot"] false
|
||||||
["result",0,"message","from","first_name"] "Kay"
|
["result",0,"message","from","first_name"] "Kay"
|
||||||
@ -11,6 +13,7 @@
|
|||||||
["result",0,"message","chat","first_name"] "Test"
|
["result",0,"message","chat","first_name"] "Test"
|
||||||
["result",0,"message","chat","last_name"] "Bot"
|
["result",0,"message","chat","last_name"] "Bot"
|
||||||
["result",0,"message","chat","username"] "BotTest"
|
["result",0,"message","chat","username"] "BotTest"
|
||||||
|
["result",0,"message","chat","title"] "BotTestTitle"
|
||||||
["result",0,"message","chat","type"] "private"
|
["result",0,"message","chat","type"] "private"
|
||||||
["result",0,"message","date"] 1555822879
|
["result",0,"message","date"] 1555822879
|
||||||
["result",0,"message","reply_to_message","message_id"] 6542
|
["result",0,"message","reply_to_message","message_id"] 6542
|
||||||
@ -32,7 +35,6 @@
|
|||||||
["result",0,"message","reply_to_message","entities",1,"offset"] 61
|
["result",0,"message","reply_to_message","entities",1,"offset"] 61
|
||||||
["result",0,"message","reply_to_message","entities",1,"length"] 5
|
["result",0,"message","reply_to_message","entities",1,"length"] 5
|
||||||
["result",0,"message","reply_to_message","entities",1,"type"] "bot_command"
|
["result",0,"message","reply_to_message","entities",1,"type"] "bot_command"
|
||||||
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
|
||||||
["result",0,"message","forward_from","id"] 123456789
|
["result",0,"message","forward_from","id"] 123456789
|
||||||
["result",0,"message","forward_from","is_bot"] false
|
["result",0,"message","forward_from","is_bot"] false
|
||||||
["result",0,"message","forward_from","first_name"] "Kay"
|
["result",0,"message","forward_from","first_name"] "Kay"
|
||||||
@ -40,13 +42,20 @@
|
|||||||
["result",0,"message","forward_from","username"] "Gnadelwartz"
|
["result",0,"message","forward_from","username"] "Gnadelwartz"
|
||||||
["result",0,"message","forward_from","language_code"] "de"
|
["result",0,"message","forward_from","language_code"] "de"
|
||||||
["result",0,"message","forward_date"] 1555822879
|
["result",0,"message","forward_date"] 1555822879
|
||||||
["result",0,"message","photo",0,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC"
|
["result",0,"message","audio","file_id"] "audio-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
["result",0,"message","video","file_id"] "video-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
["result",0,"message","document","file_id"] "document-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
["result",0,"message","sticker","file_id"] "sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
["result",0,"message","sticker","file_id"] "sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
["result",0,"message","voice","file_id"] "voice-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
|
|
||||||
|
["result",0,"message","photo",0,"file_id"] "photo-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa"
|
||||||
["result",0,"message","photo",0,"file_size"] 1468
|
["result",0,"message","photo",0,"file_size"] 1468
|
||||||
["result",0,"message","photo",0,"width"] 67
|
["result",0,"message","photo",0,"width"] 67
|
||||||
["result",0,"message","photo",0,"height"] 90
|
["result",0,"message","photo",0,"height"] 90
|
||||||
["result",0,"message","photo",0] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC","file_size":1468,"width":67,"height":90}
|
["result",0,"message","photo",0] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC","file_size":1468,"width":67,"height":90}
|
||||||
["result",0,"message","photo",1,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC"
|
["result",0,"message","photo",1,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC"
|
||||||
["result",0,"message","photo",1,"file_size"] 25125
|
["result",0,"message","photo",1,"file_size"] 2512
|
||||||
["result",0,"message","photo",1,"width"] 240
|
["result",0,"message","photo",1,"width"] 240
|
||||||
["result",0,"message","photo",1,"height"] 320
|
["result",0,"message","photo",1,"height"] 320
|
||||||
["result",0,"message","photo",1] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC","file_size":25125,"width":240,"height":320}
|
["result",0,"message","photo",1] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC","file_size":25125,"width":240,"height":320}
|
||||||
|
@ -6,7 +6,7 @@ CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS
|
|||||||
CHAT: FIRST_NAME Test
|
CHAT: FIRST_NAME Test
|
||||||
CHAT: ID 123456789
|
CHAT: ID 123456789
|
||||||
CHAT: LAST_NAME Bot
|
CHAT: LAST_NAME Bot
|
||||||
CHAT: TITLE
|
CHAT: TITLE BotTestTitle
|
||||||
CHAT: TYPE private
|
CHAT: TYPE private
|
||||||
CHAT: USERNAME BotTest
|
CHAT: USERNAME BotTest
|
||||||
REPLYTO: 0 Ich bin der Deal-O-Mat Bot. Für eine Liste der Befehle sende /help
|
REPLYTO: 0 Ich bin der Deal-O-Mat Bot. Für eine Liste der Befehle sende /help
|
||||||
@ -20,12 +20,12 @@ FORWARD: ID 6541
|
|||||||
FORWARD: LAST_NAME M
|
FORWARD: LAST_NAME M
|
||||||
FORWARD: UID 123456789
|
FORWARD: UID 123456789
|
||||||
FORWARD: USERNAME Gnadelwartz
|
FORWARD: USERNAME Gnadelwartz
|
||||||
URLS: AUDIO
|
URLS: AUDIO audio-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
URLS: DOCUMENT
|
URLS: DOCUMENT document-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
URLS: PHOTO AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC
|
URLS: PHOTO photo-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
URLS: STICKER
|
URLS: STICKER sticker-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
URLS: VIDEO
|
URLS: VIDEO video-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
URLS: VOICE AwADAgADOAQAAqd24Emnm_VGmmVEuAI
|
URLS: VOICE voice-AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa
|
||||||
CONTACT: FIRST_NAME ADAC
|
CONTACT: FIRST_NAME ADAC
|
||||||
CONTACT: LAST_NAME Pannenhilfe
|
CONTACT: LAST_NAME Pannenhilfe
|
||||||
CONTACT: NUMBER 222222
|
CONTACT: NUMBER 222222
|
||||||
|
Loading…
Reference in New Issue
Block a user