From 54c71868489c122e3c6a96e13f3e622df72db2e0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 19 Jan 2016 14:17:06 +0100 Subject: [PATCH] Update bashbot.sh --- bashbot.sh | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 89441c8..7d5b024 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -32,24 +32,36 @@ FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/' UPD_URL=$URL'/getUpdates?offset=' GET_URL=$URL'/getFile' OFFSET=0 -declare -A USER URLS CONTACT LOCATION +declare -A USER MESSAGE send_message() { local chat="$1" - local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myimagelocationstartshere.*//g')" - local keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myimagelocationstartshere.*//g')" - local image="$(echo "$2" | sed '/myimagelocationstartshere /!d;s/.*myimagelocationstartshere //g;s/ mykeyboardstartshere.*//g;')" + local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g')" + + local keyboard="$(echo "$2" | sed '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g')" + + local file="$(echo "$2" | sed '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ mykeyboardstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g')" + + local lat="$(echo "$2" | sed '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylongstartshere.*//g')" + + local long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g')" + if [ "$keyboard" != "" ]; then send_keyboard "$chat" "$text" "$keyboard" local sent=y fi - if [ "$image" != "" ]; then - send_photo "$chat" "$image" + if [ "$file" != "" ]; then + send_file "$chat" "$file" local sent=y fi if [ "$sent" != "y" ];then res=$(curl -s "$MSG_URL" -F "chat_id=$chat" -F "text=$text") fi + + if [ "$lat" != "" -a "$long" != "" ]; then + send_location "$chat" "$lat" "$long" + local sent=y + fi } send_keyboard() { @@ -70,9 +82,9 @@ get_file() { send_file() { [ "$2" = "" ] && return - chat_id=$1 - file=$2 - ext="${file##*.}" + local chat_id=$1 + local file=$2 + local ext="${file##*.}" case $ext in "mp3") CUR_URL=$AUDIO_URL @@ -154,11 +166,11 @@ process_client() { USER[USERNAME]=$(echo "$res" | egrep '\["result",0,"message","chat","username"\]' | cut -f 2 | cut -d '"' -f 2) # Audio - URLS[AUDIO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","audio","file_id"\]' | cut -f 2 | cut -d '"' -f 2)) + MESSAGE[AUDIO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","audio","file_id"\]' | cut -f 2 | cut -d '"' -f 2)) # Documenr - URLS[DOCUMENT]=$(get_file $(echo "$res" | egrep '\["result",0,"message","document","file_id"\]' | cut -f 2 | cut -d '"' -f 2)) + MESSAGE[DOCUMENT]=$(get_file $(echo "$res" | egrep '\["result",0,"message","document","file_id"\]' | cut -f 2 | cut -d '"' -f 2)) # Photo - URLS[PHOTO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","photo",.*,"file_id"\]' | cut -f 2 | cut -d '"' -f 2 | sed -n '$p')) + MESSAGE[PHOTO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","photo",.*,"file_id"\]' | cut -f 2 | cut -d '"' -f 2 | sed -n '$p')) # Sticker URLS[STICKER]=$(get_file $(echo "$res" | egrep '\["result",0,"message","sticker","file_id"\]' | cut -f 2 | cut -d '"' -f 2)) # Video @@ -230,7 +242,7 @@ while true; do { # Offset OFFSET=$(echo "$res" | egrep '\["result",0,"update_id"\]' | cut -f 2) # Message - MESSAGE=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2) + MESSAGE[MESSAGE]=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2) OFFSET=$((OFFSET+1)) @@ -241,4 +253,3 @@ while true; do { }; done -