mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-21 23:25:08 +00:00
multitasking
added process_client to manage multi client at same time fixed function to work with nohup
This commit is contained in:
parent
7f3e717f77
commit
fb9c9923a9
21
bashbot.sh
21
bashbot.sh
@ -17,14 +17,25 @@ PHO_URL=$URL'/sendPhoto'
|
||||
UPD_URL=$URL'/getUpdates?offset='
|
||||
OFFSET=0
|
||||
|
||||
function send_message {
|
||||
send_message() {
|
||||
res=$(curl "$MSG_URL" -F "chat_id=$1" -F "text=$2")
|
||||
}
|
||||
|
||||
function send_photo() {
|
||||
send_photo() {
|
||||
res=$(curl "$PHO_URL" -F "chat_id=$1" -F "photo=@$2")
|
||||
}
|
||||
|
||||
process_client() {
|
||||
local MESSAGE=$1
|
||||
local TARGET=$2
|
||||
local msg=""
|
||||
case $MESSAGE in
|
||||
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
|
||||
*) msg="$MESSAGE";;
|
||||
esac
|
||||
send_message "$TARGET" "$msg"
|
||||
}
|
||||
|
||||
while true; do {
|
||||
|
||||
res=$(curl $UPD_URL$OFFSET)
|
||||
@ -36,11 +47,7 @@ while true; do {
|
||||
OFFSET=$((OFFSET+1))
|
||||
|
||||
if [ $OFFSET != 1 ]; then
|
||||
case $MESSAGE in
|
||||
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
|
||||
*) msg="$MESSAGE";;
|
||||
esac
|
||||
send_message "$TARGET" "$msg"
|
||||
process_client "$MESSAGE" "$TARGET" &
|
||||
fi
|
||||
|
||||
} &>/dev/null; done
|
||||
|
Loading…
Reference in New Issue
Block a user