mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-29 16:30:52 +00:00
Finished!
This commit is contained in:
parent
54c7186848
commit
329b248987
34
bashbot.sh
34
bashbot.sh
|
@ -12,7 +12,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.
|
||||||
# If you're in Europe, and public domain does not exist, then haha.
|
# If you're in Europe, and public domain does not exist, then haha.
|
||||||
|
|
||||||
TOKEN='tokenhere'
|
TOKEN='179533649:AAHR470oLFSDD8WXy8L87uZFofxM6IDp5oU'
|
||||||
URL='https://api.telegram.org/bot'$TOKEN
|
URL='https://api.telegram.org/bot'$TOKEN
|
||||||
|
|
||||||
FORWARD_URL=$URL'/forwardMessage'
|
FORWARD_URL=$URL'/forwardMessage'
|
||||||
|
@ -32,7 +32,7 @@ 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 MESSAGE
|
declare -A USER MESSAGE URLS CONTACT LOCATION
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
local chat="$1"
|
local chat="$1"
|
||||||
|
@ -54,14 +54,15 @@ send_message() {
|
||||||
send_file "$chat" "$file"
|
send_file "$chat" "$file"
|
||||||
local sent=y
|
local sent=y
|
||||||
fi
|
fi
|
||||||
if [ "$sent" != "y" ];then
|
|
||||||
res=$(curl -s "$MSG_URL" -F "chat_id=$chat" -F "text=$text")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$lat" != "" -a "$long" != "" ]; then
|
if [ "$lat" != "" -a "$long" != "" ]; then
|
||||||
send_location "$chat" "$lat" "$long"
|
send_location "$chat" "$lat" "$long"
|
||||||
local sent=y
|
local sent=y
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$sent" != "y" ];then
|
||||||
|
res=$(curl -s "$MSG_URL" -F "chat_id=$chat" -F "text=$text")
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send_keyboard() {
|
send_keyboard() {
|
||||||
|
@ -119,7 +120,7 @@ send_file() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
send_action $chat_id $STATUS
|
send_action $chat_id $STATUS
|
||||||
res=$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file")
|
res=$(curl -s "$CUR_URL" -F "chat_id=$chat_id" -F "$WHAT=@$file" -F "caption=$3")
|
||||||
}
|
}
|
||||||
|
|
||||||
# typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location
|
# typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location
|
||||||
|
@ -166,11 +167,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
|
||||||
MESSAGE[AUDIO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","audio","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
URLS[AUDIO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","audio","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
||||||
# Documenr
|
# Document
|
||||||
MESSAGE[DOCUMENT]=$(get_file $(echo "$res" | egrep '\["result",0,"message","document","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
URLS[DOCUMENT]=$(get_file $(echo "$res" | egrep '\["result",0,"message","document","file_id"\]' | cut -f 2 | cut -d '"' -f 2))
|
||||||
# Photo
|
# Photo
|
||||||
MESSAGE[PHOTO]=$(get_file $(echo "$res" | egrep '\["result",0,"message","photo",.*,"file_id"\]' | cut -f 2 | cut -d '"' -f 2 | sed -n '$p'))
|
URLS[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
|
||||||
|
@ -190,6 +191,7 @@ process_client() {
|
||||||
# Location
|
# Location
|
||||||
LOCATION[LONGITUDE]=$(echo "$res" | egrep '\["result",0,"message","location","longitude"\]' | cut -f 2 | cut -d '"' -f 2)
|
LOCATION[LONGITUDE]=$(echo "$res" | egrep '\["result",0,"message","location","longitude"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
LOCATION[LATITUDE]=$(echo "$res" | egrep '\["result",0,"message","location","latitude"\]' | cut -f 2 | cut -d '"' -f 2)
|
LOCATION[LATITUDE]=$(echo "$res" | egrep '\["result",0,"message","location","latitude"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
NAME="$(basename ${URLS[*]})"
|
||||||
|
|
||||||
# Tmux
|
# Tmux
|
||||||
copname="CO${USER[ID]}"
|
copname="CO${USER[ID]}"
|
||||||
|
@ -197,6 +199,10 @@ process_client() {
|
||||||
copid="$(cat $copidname 2>/dev/null)"
|
copid="$(cat $copidname 2>/dev/null)"
|
||||||
|
|
||||||
if [ "$copid" = "" ]; then
|
if [ "$copid" = "" ]; then
|
||||||
|
curl -s ${URLS[*]} -o $NAME
|
||||||
|
send_file "${USER[ID]}" "$NAME" "$CAPTION"
|
||||||
|
rm "$NAME"
|
||||||
|
send_location "${USER[ID]}" "${LOCATION[LATITUDE]}" "${LOCATION[LONGITUDE]}"
|
||||||
case $MESSAGE in
|
case $MESSAGE in
|
||||||
'/question')
|
'/question')
|
||||||
startproc&
|
startproc&
|
||||||
|
@ -208,14 +214,14 @@ process_client() {
|
||||||
send_message "${USER[ID]}" "This is bashbot, the Telegram bot written entirely in bash.
|
send_message "${USER[ID]}" "This is bashbot, the Telegram bot written entirely in bash.
|
||||||
Features background tasks and interactive chats.
|
Features background tasks and interactive chats.
|
||||||
Can serve as an interface for cli programs.
|
Can serve as an interface for cli programs.
|
||||||
Currently can send messages, custom keyboards and photos.
|
Currently can send, recieve and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
|
||||||
Available commands:
|
Available commands:
|
||||||
/start: Start bot and get this message.
|
/start: Start bot and get this message.
|
||||||
/info: Get shorter info message about this bot.
|
/info: Get shorter info message about this bot.
|
||||||
/question: Start interactive chat.
|
/question: Start interactive chat.
|
||||||
/cancel: Cancel any currently running interactive chats.
|
/cancel: Cancel any currently running interactive chats.
|
||||||
Written by @topkecleon, Juan Potato (@awkward_potato), Lorenzo Santina (BigNerd95) and Daniil Gentili (danog)
|
Written by @topkecleon, Juan Potato (@awkward_potato), Lorenzo Santina (BigNerd95) and Daniil Gentili (danog)
|
||||||
https://github.com/topkecleon/telegram-bot-bash
|
Contribute to the project: https://github.com/topkecleon/telegram-bot-bash
|
||||||
"
|
"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -242,7 +248,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[MESSAGE]=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
MESSAGE=$(echo "$res" | egrep '\["result",0,"message","text"\]' | cut -f 2 | cut -d '"' -f 2)
|
||||||
|
|
||||||
OFFSET=$((OFFSET+1))
|
OFFSET=$((OFFSET+1))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user