mirror of
https://github.com/danog/id3bot.git
synced 2024-12-02 09:17:53 +01:00
Update bashbot.sh
This commit is contained in:
parent
501b757ac2
commit
54c7186848
39
bashbot.sh
39
bashbot.sh
@ -32,24 +32,36 @@ FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
|||||||
UPD_URL=$URL'/getUpdates?offset='
|
UPD_URL=$URL'/getUpdates?offset='
|
||||||
GET_URL=$URL'/getFile'
|
GET_URL=$URL'/getFile'
|
||||||
OFFSET=0
|
OFFSET=0
|
||||||
declare -A USER URLS CONTACT LOCATION
|
declare -A USER MESSAGE
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
local chat="$1"
|
local chat="$1"
|
||||||
local text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myimagelocationstartshere.*//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/ myimagelocationstartshere.*//g')"
|
|
||||||
local image="$(echo "$2" | sed '/myimagelocationstartshere /!d;s/.*myimagelocationstartshere //g;s/ mykeyboardstartshere.*//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
|
if [ "$keyboard" != "" ]; then
|
||||||
send_keyboard "$chat" "$text" "$keyboard"
|
send_keyboard "$chat" "$text" "$keyboard"
|
||||||
local sent=y
|
local sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$image" != "" ]; then
|
if [ "$file" != "" ]; then
|
||||||
send_photo "$chat" "$image"
|
send_file "$chat" "$file"
|
||||||
local sent=y
|
local sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$sent" != "y" ];then
|
if [ "$sent" != "y" ];then
|
||||||
res=$(curl -s "$MSG_URL" -F "chat_id=$chat" -F "text=$text")
|
res=$(curl -s "$MSG_URL" -F "chat_id=$chat" -F "text=$text")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$lat" != "" -a "$long" != "" ]; then
|
||||||
|
send_location "$chat" "$lat" "$long"
|
||||||
|
local sent=y
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
send_keyboard() {
|
send_keyboard() {
|
||||||
@ -70,9 +82,9 @@ get_file() {
|
|||||||
|
|
||||||
send_file() {
|
send_file() {
|
||||||
[ "$2" = "" ] && return
|
[ "$2" = "" ] && return
|
||||||
chat_id=$1
|
local chat_id=$1
|
||||||
file=$2
|
local file=$2
|
||||||
ext="${file##*.}"
|
local ext="${file##*.}"
|
||||||
case $ext in
|
case $ext in
|
||||||
"mp3")
|
"mp3")
|
||||||
CUR_URL=$AUDIO_URL
|
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)
|
USER[USERNAME]=$(echo "$res" | egrep '\["result",0,"message","chat","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
|
||||||
# Audio
|
# 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
|
# 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
|
# 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
|
# Sticker
|
||||||
URLS[STICKER]=$(get_file $(echo "$res" | egrep '\["result",0,"message","sticker","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
URLS[STICKER]=$(get_file $(echo "$res" | egrep '\["result",0,"message","sticker","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
||||||
# Video
|
# Video
|
||||||
@ -230,7 +242,7 @@ while true; do {
|
|||||||
# Offset
|
# Offset
|
||||||
OFFSET=$(echo "$res" | egrep '\["result",0,"update_id"\]' | cut -f 2)
|
OFFSET=$(echo "$res" | egrep '\["result",0,"update_id"\]' | cut -f 2)
|
||||||
# Message
|
# 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))
|
OFFSET=$((OFFSET+1))
|
||||||
|
|
||||||
@ -241,4 +253,3 @@ while true; do {
|
|||||||
|
|
||||||
}; done
|
}; done
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user