mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-29 16:30:52 +00:00
Added option to download photos
This commit is contained in:
parent
641c55628d
commit
c5ef39b9f3
11
bashbot.sh
11
bashbot.sh
|
@ -16,6 +16,7 @@ TOKEN='tokenhere'
|
||||||
URL='https://api.telegram.org/bot'$TOKEN
|
URL='https://api.telegram.org/bot'$TOKEN
|
||||||
MSG_URL=$URL'/sendMessage'
|
MSG_URL=$URL'/sendMessage'
|
||||||
PHO_URL=$URL'/sendPhoto'
|
PHO_URL=$URL'/sendPhoto'
|
||||||
|
FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
||||||
UPD_URL=$URL'/getUpdates?offset='
|
UPD_URL=$URL'/getUpdates?offset='
|
||||||
OFFSET=0
|
OFFSET=0
|
||||||
|
|
||||||
|
@ -68,8 +69,10 @@ startproc() {
|
||||||
inproc() {
|
inproc() {
|
||||||
local copname="$1"
|
local copname="$1"
|
||||||
local copid="$2"
|
local copid="$2"
|
||||||
|
local MESSAGE="$3"
|
||||||
|
local PHOTO_ID="$4"
|
||||||
shift 2
|
shift 2
|
||||||
tmux send-keys -t $copname "$@
|
tmux send-keys -t $copname "$MESSAGE
|
||||||
"
|
"
|
||||||
ps aux | grep -v grep | grep -q "$copid" || { rm -r $copname; };
|
ps aux | grep -v grep | grep -q "$copid" || { rm -r $copname; };
|
||||||
}
|
}
|
||||||
|
@ -77,6 +80,7 @@ inproc() {
|
||||||
process_client() {
|
process_client() {
|
||||||
local MESSAGE=$1
|
local MESSAGE=$1
|
||||||
local TARGET=$2
|
local TARGET=$2
|
||||||
|
local PHOTO_ID=$3
|
||||||
local msg=""
|
local msg=""
|
||||||
local copname="CO$TARGET"
|
local copname="CO$TARGET"
|
||||||
local copidname="$copname/pid"
|
local copidname="$copname/pid"
|
||||||
|
@ -115,7 +119,7 @@ https://github.com/topkecleon/telegram-bot-bash
|
||||||
rm -r $copname
|
rm -r $copname
|
||||||
send_message "$TARGET" "Command canceled."
|
send_message "$TARGET" "Command canceled."
|
||||||
;;
|
;;
|
||||||
*) inproc "$copname" "$copid" "$MESSAGE";;
|
*) inproc "$copname" "$copid" "$MESSAGE" "$PHOTO_ID";;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -127,11 +131,12 @@ while true; do {
|
||||||
TARGET=$(echo $res | ./JSON.sh | egrep '\["result",0,"message","chat","id"\]' | cut -f 2)
|
TARGET=$(echo $res | ./JSON.sh | egrep '\["result",0,"message","chat","id"\]' | cut -f 2)
|
||||||
OFFSET=$(echo $res | ./JSON.sh | egrep '\["result",0,"update_id"\]' | cut -f 2)
|
OFFSET=$(echo $res | ./JSON.sh | egrep '\["result",0,"update_id"\]' | cut -f 2)
|
||||||
MESSAGE=$(echo $res | ./JSON.sh -s | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
MESSAGE=$(echo $res | ./JSON.sh -s | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
PHOTO_ID=$(echo $res | ./JSON.sh -s | egrep '\["result",0,"message","photo",.*,"file_id"\]' | cut -f 2 | cut -d '"' -f 2 | sed -n '$p')
|
||||||
|
|
||||||
OFFSET=$((OFFSET+1))
|
OFFSET=$((OFFSET+1))
|
||||||
|
|
||||||
if [ $OFFSET != 1 ]; then
|
if [ $OFFSET != 1 ]; then
|
||||||
process_client "$MESSAGE" "$TARGET"&
|
process_client "$MESSAGE" "$TARGET" "$PHOTO_ID"&
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}; done
|
}; done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user