mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-06-03 19:00:50 +00:00
Merge pull request #2 from bignerd95/multitasking-branch
Multitasking branch
This commit is contained in:
commit
c6c524b2c8
23
bashbot.sh
23
bashbot.sh
|
@ -1,5 +1,5 @@
|
||||||
# bashbot, the Telegram bot written in bash.
|
# bashbot, the Telegram bot written in bash.
|
||||||
# Written by @topkecleon and Juan Potato (@awkward_potato)
|
# Written by @topkecleon, Juan Potato (@awkward_potato) and Lorenzo Santina (BigNerd95)
|
||||||
# http://github.com/topkecleon/bashbot
|
# http://github.com/topkecleon/bashbot
|
||||||
|
|
||||||
# Depends on JSON.sh (http://github.com/dominictarr/JSON.sh),
|
# Depends on JSON.sh (http://github.com/dominictarr/JSON.sh),
|
||||||
|
@ -17,14 +17,25 @@ PHO_URL=$URL'/sendPhoto'
|
||||||
UPD_URL=$URL'/getUpdates?offset='
|
UPD_URL=$URL'/getUpdates?offset='
|
||||||
OFFSET=0
|
OFFSET=0
|
||||||
|
|
||||||
function send_message {
|
send_message() {
|
||||||
res=$(curl "$MSG_URL" -F "chat_id=$1" -F "text=$2")
|
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")
|
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 {
|
while true; do {
|
||||||
|
|
||||||
res=$(curl $UPD_URL$OFFSET)
|
res=$(curl $UPD_URL$OFFSET)
|
||||||
|
@ -36,11 +47,7 @@ while true; do {
|
||||||
OFFSET=$((OFFSET+1))
|
OFFSET=$((OFFSET+1))
|
||||||
|
|
||||||
if [ $OFFSET != 1 ]; then
|
if [ $OFFSET != 1 ]; then
|
||||||
case $MESSAGE in
|
process_client "$MESSAGE" "$TARGET" &
|
||||||
'/info') msg="This is bashbot, the Telegram bot written entirely in bash.";;
|
|
||||||
*) msg="$MESSAGE";;
|
|
||||||
esac
|
|
||||||
send_message "$TARGET" "$msg"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
} &>/dev/null; done
|
} &>/dev/null; done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user